Julius Plenz – Blog

git tracking branch management

There are different approaches 'round the net on how to deal with git remote tracking branches in an effecient way. Some people have written Ruby gems (uggh) that introduce lots of not-so-intuitive git subcommands to manage all kinds of tracking branches.

In recent versions of Git however, I have no need for these scripts. I can live with the following aliases:

lu = log ..@{u}
ft = merge --ff-only @{u}
track = branch --set-upstream

To track a branch, I enter git track master origin/master, for example. (By the way, if you create a new branch and want to push it to a remote, use push -u – it will automatically set up your current branch to track the remote branch you just created.)

Then, my regular workflow looks like this:

$ git remote update     # fetch changes
$ git lu                # log ..upstream -- review changes
$ git ft                # ff tracking branch -- integrate

The key here is using @{u}, which is a short form of @{upstream}, a reference to the upstream branch (that is, the branch your HEAD is tracking). This special notation first appeared in Git 1.7.0.

If you're not sure about the current status of your branches and what they are tracking, simply use git branch -vv. You'll find the tracking information in brackets just before the commit description.

posted 2011-02-10 tagged git