How to Update a Git Fork from Master

Since I keep forgetting it myself all the time here's a quick rundown on how to update your fork with the changes from the original master repository. Github will be used as an example here, but this does of course work for gitlab or bitbucket, etc ... as well.

  1. Open the console and make sure you are on your local master branch.
git checkout master
  1. Next add the original repository as upstream.
git remote add upstream https://github.com/original/repo.git
  1. Fetch the upstream changes from the master repo.
git fetch upstream
  1. Rebase. If you have unstashed changes, git will ask you to stash them. Do it.
git rebase upstream/master
First, rewinding head to replay your work on top of it...
Fast-forwarded master to upstream/master.
  1. Check your remotes. Origin should be your fork, upstream the original repo.
git remote -v
origin  https://github.com/myfork/repo.git (fetch)
origin  https://github.com/myfork/repo.git (push)
upstream  https://github.com/original/repo.git (fetch)
upstream  https://github.com/original/repo.git (push)
  1. If origin does not show your fork, manually set it again.
git remote set-url origin https://github.com/myfork/repo.git
  1. Finally, push the changes to your forks remote.
git push origin master

And that's it ... easy as 1 2 3, right? Next you'll probably want to unstash your changes and merge where necessary.

If you are using Github, their website should now show This branch is even with original:master.

Congrats =)