How to Update a Github Fork

January 10, 2013

Once upon a time you found a project on Github that caught your fancy and you made a fork of your very own. You made some changes and time passed. Now you realize that the original project has some new features you want in your fork. What to do?

Step 1

Add a remote to the original, or upstream project.

$ git remote add upstream git://github.com/originalOwner/project.git

You can confirm the remote with this command:

$ git remote -v

There will (at least) be a pair of references to origin (your fork of the project) and a pair of references to upstream, the new remote you've added for the upstream project.

Step 2

Fetch all the changes from the upstream project. This will gather all the branches of that upstream project.

$ git fetch upstream

Step 3

Make sure you are on the master branch of your local repository:

$ git checkout master

Step 4

Rebase your branch so that any changes you've made which aren't in the upstream repository are replayed, thus preventing you from losing them.

$ git rebase upstream/master

Step 5

Push your newly updated local repository to your Github fork. You may need to add the -f flag to force the push on the initial push after a rebase.

$ git push [-f] origin master
Author's profile picture

Mark H. Nichols

I am a husband, cellist, code prole, nerd, technologist, and all around good guy living and working in fly-over country. You should follow me on Twitter.