AI Hints
Home›Git & GitHub Tutorial›Forks and Open Source
Git & GitHub · Lesson 76 of 144

Keeping a Fork Updated

The upstream remote.

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

The original project keeps moving. New commits arrive every day, but your fork doesn't get them automatically. To keep up, you add a second remote, pointing to the original. By tradition, it's called upstream.

Keeping a Fork Updated
From the video: Keeping a Fork Updated
  • The original keeps moving
  • Your fork falls behind
  • Add a remote called upstream

Adding upstream

Git remote add upstream, with the original project's address. Now git remote dash v shows two remotes. Origin is our fork. Upstream is the original.

git
git remote add upstream https://github.com/octo/awesome-tips.git
git remote -v
origin  https://github.com/sam/awesome-tips.git (fetch)
origin  https://github.com/sam/awesome-tips.git (push)
upstream        https://github.com/octo/awesome-tips.git (fetch)
upstream        https://github.com/octo/awesome-tips.git (push)

Syncing

The original project got a new tip. To bring it in, git fetch upstream. Then merge upstream slash main into our main. Finally push, so our fork on GitHub is up to date too.

git
git fetch upstream
From https://github.com/octo/awesome-tips
 * [new branch]      main       -> upstream/main
git merge upstream/main
Updating b06f74c..c0a9ac0
Fast-forward
 tips.md | 1 +
 1 file changed, 1 insertion(+)
git push
To https://github.com/sam/awesome-tips.git
   b06f74c..c0a9ac0  main -> main

Summary

Add the original as upstream. Fetch upstream, merge upstream slash main, then push to your fork. Next, your first open source contribution.

Key takeaways
  • git remote add upstream <url>
  • git fetch upstream
  • git merge upstream/main
Next up: Contributing to Open Source — a friendly first pull request