Keep up-to-date on forked repositories

I usually fetch the upstream repository and merge it into my local repository, then upload all the merges into the github repository. That works sometimes, but it also fails sometimes with me having an extra commit with merges leaving the git history different from the upstream…

This snippet has been taken from github.community.

git checkout master # Make sure you always run the following commands from the master branch
git fetch --all
git pull --rebase upstream master
git push origin master

This will rebase the upstream changes on your local forked version so the master branch git history will look exactly the same at the end.