git ready

learn git one commit at a time
by Nick Quaranto

easily fetching upstream changes

committed 12 Feb 2009

This tip comes from Dav Glass, whose work on YUI at GitHub requires him to bring in commits frequently. So, he’s created a helpful alias so he can merge in changes easily.

First off, he’s got a consistent naming scheme for his upstream remote:

git remote add upstream git://github.com/user/repo.git

Just throw this in your .gitconfig and you’re all set:

[alias]
  pu = !"git fetch origin -v; git fetch upstream -v; git merge upstream/master"

Now git pu will grab all of the latest changes from both remotes, and then merge in the commits from upstream.

How is this different from just doing a git pull upstream master? This brings in changes from two different sources: his own fork and the main repository (the upstream). Doing a pull usually only brings changes in from one source. If you’re confused about how this works, check out the History section of Git for Computer Scientists for some graphs on how the fetching and merging process works.

Of course, there’s plenty of different ways you could tackle this problem. For example, you could use rebase or even pull with rebase instead of merging. It all depends on how you want to organize your repository’s history, and what’s easiest for you.

If you have aliases or suggestions to make this process easier, let us know!