Apr 18, 2012

How to fetch upstream changes in git easily

It is quite common to update your git fork repository with the upstream changes.

Here it is the workflow I use to keep synchronize my branch with Octopress.

  • First of all, we should configure the remotes.
$ git remote add upstream git://github.com/imathis/octopress.git
  • Check the remotes
    $ git remote
  • Merge/Rebase the changes
    $ git fetch origin -v
$ git fetch upstream -v
$ git merge upstream/master

If you prefere you can create an alias in your .gitconfig.

  pull_upstream = !"git fetch origin -v; git fetch upstream -v; git merge upstream/master"

Now git pull_upstream will fetch the changes of both remotes, and the merge in the upstream changes.