In the previous chapter, we covered pull requests and forks. But one very important point was missing: how do you get the original project’s new changes into your fork?

The problem

Your fork is a copy of the project, taken at a given moment. While you work, other developers get their pull requests merged into the original project. Your fork doesn’t update itself.

The solution: the upstream remote

Your local project knows two remote repositories:

RemotePoints toUsed to
originYour forkPush your changes
upstreamThe original projectGet the latest changes
Original projectupstreamYour forkoriginYour machinelocalForkPull requestgit clonegit push origingit pull upstream
Pull from upstream, push to origin, and the pull request takes the last step.

To see the configured remotes, open the project’s .git/config file, or run:

git remote -v
# origin    https://github.com/your-account/the-project.git (fetch)
# origin    https://github.com/your-account/the-project.git (push)
# upstream  https://github.com/owner/the-project.git (fetch)
# upstream  https://github.com/owner/the-project.git (push)

Some tools, like GitHub Desktop, add upstream automatically. If it’s missing, add it by hand, with the original project’s URL:

git remote add upstream https://github.com/owner/the-project.git

Get the changes

git pull upstream master

Replace master with the branch you want to pull.

The full cycle

# Get the latest from the original project
git pull upstream master

# Send your changes to your fork
git push origin feature/1

# Then open a pull request to the original project

Remember the rule: pull from upstream, push to origin. Pushes always go to your fork, and the pull request is what brings the changes into the original project.

Exercise · Add the missing remote

git remote -v only shows origin. The original project is https://github.com/symfony/demo.git, and its main branch is main. Add upstream, then get its latest changes.

Show the solution
git remote add upstream https://github.com/symfony/demo.git
git remote -v
git pull upstream main

What’s Next

Create enough branches and the list grows fast. In the next chapter, we clean up branches.


This is Chapter 9 of the Git in Practice course. Follow along to learn how to use Git every day and as a team.