Posted on

More Info From Git Branches

For those of you that follow our posts on a regular basis, you’ll know we are somewhat biased toward using Git for version control.   While Git takes some getting used to, once you have the basics down it is a very powerful tool.   As you become more familiar with Git, you start to realize there are quite a few “power tools” available to you that let you delve deeper into the history of your project.   The following article posted by Eric Ritz on our corporate mailing list provides yet another useful tip on how to get more from Git.  Enjoy!

– Lance

Something I don’t see advertised very much is the fact that git-branch has a verbose parameter: ‘–verbose’, or just ‘-v’.  This parameter will show you which commit each branch is currently pointing to.

For example, from my copy of the Panhandler repo:

$ git branch -v
driver/commission-junction 9c9721e CJ: Implement set_results_page()
driver/ebay                e1f86f3 eBay: Update test script to test recent API changes
master                     599a2db Document the type of each member of PanhandlerProduct
* phpunit-test               19d97e5 TEMP Skip one test since I don’t have a connection

If you use the parameter twice you will get an additional piece of information: the upstream branch for each branch (if any) and how many commits separate the two.  As an example, this is from the MoneyPress Commission Junction repo:

$ git branch -vv
* (no branch) bc97baa Disable curl peer verification check
master      7f0b529 [origin/master: behind 27] Remove the old keywords.php
next        88a41ec [origin/next] Update version and update history for v1.0.4

The difference here is the inclusion of the upstream branches in braces.  And in the case of ‘master’ I see how far behind I am.

If you want a quick overview of where every branch is, then ‘git branch -vv’ is a useful way to get that.  Or ‘git branch -avv’ if you want to see all the remote branches too.  Personally, I find this useful after fetching a lot of updates, as it lets me see how far behind my tracking branches are.  It’s also a quick way to tell if multiple branches are pointing to the same commit, which I occasionally want to know.

You may find it useful in those or other situations.