Updating a Github Fork from the Original Repository

Seems like everyone these days are switching from SVN to git. I think it’s an awesome choose and I really like learning as much about git as I can. Something that is not quite clear when you are using github is how do you update a project that you have forked from someone else’s repo? Well if you are like me I don’t use git on a daily bases yet so I was not quite sure how this was done. After spending 10 min or so reading some blog posts this is what I found.

The following will only work if you have checked out a repo that you have forked and you have things setup correct. I am assuming that you have at least gotten as far as the basics of setting up git on your machine and you have forked someone else’s code on github

First you need to add a remote branch to your repository that points to the original repo you forked from.

git remote add --track master benstucki git://github.com/benstucki/reflex.git

You will want to replace ‘master’ with the branch you want to track in the remote repo. In most cases this will be master, although you could replace it with edge or any other branch. You should also replace ‘benstucki’ is what you the remote will be called.

To verify the remote repository was added run

git remote

You should see the new remote repo, in this case named ‘benstucki’, along with any other remote repositories you may have previously added.

Now we can fetch all the changes from benstucki’s code base.

git fetch benstucki

This will create a new remote branch called ‘benstucki/master’. Now we are ready to merge the code from the remote repository.

git merge benstucki/master

That’s it. Remember, this process isn’t limited only to the original repository. Feel free to add remote branches for other user’s forks or even from repositories outside Github.

After you have followed the steps above all that is left to do is merge like so

git merge benstucki/master