AI Hints
Home›Git & GitHub Tutorial›Practice: Remotes
Git & GitHub · Lesson 68 of 144

Practice: Two Computers

Laptop and desktop in sync.

⏱ 2 min read▶ Video at 1:14:39🎓 Free
Watch this lesson in the Git & GitHub courseWatch on YouTube ↗Full Git & GitHub course

GitHub isn't only for teams. It's also the easiest way to keep your own work in sync across two computers. Say a laptop and a desktop. The rule is simple. Pull when you sit down, push when you get up.

Practice: Two Computers
From the video: Practice: Two Computers
  • Not only for teams
  • Your laptop and your desktop
  • Pull when you sit down, push when you leave

On the laptop

On the laptop, we finish some work in a café. Commit it, and push it before closing the lid.

Laptop
echo '<p>Written in a cafe</p>' >> index.html
git commit -am "Add cafe note"
[main 4367a51] Add cafe note
 1 file changed, 1 insertion(+)
git push
To https://github.com/sam/my-site.git
   f63a17a..4367a51  main -> main

On the desktop

Back home, on the desktop, which cloned the same repository last week. First thing, git pull. The café work arrives. We carry on exactly where we left off.

Desktop
git pull
From https://github.com/sam/my-site
   f63a17a..71f58ce  main       -> origin/main
Updating f63a17a..71f58ce
Fast-forward
 index.html | 1 +
 1 file changed, 1 insertion(+)
tail -1 index.html
<p>Written in a cafe</p>

Forgot to push?

Forgot to push from the laptop? Then the desktop simply doesn't have that work yet. Nothing is lost, it's waiting on the laptop. And if you made changes on both, git pull merges them, just like with a teammate. Pull first, push last, and it just works.

Sit downgit pull
Get upgit push
Forgot?the work waits
Both changed?pull merges

Summary

Pull when you start, push when you stop, and GitHub keeps all your computers in sync. Next, the heart of teamwork on GitHub. Pull requests.

Key takeaways
  • Pull when you start
  • Push when you stop
  • Nothing is lost
Next up: What a Pull Request Is — asking to merge