Compare Commits Between Git Branches

Working with a lot of git branches can be a bit of a headache. Graph visualisations can get tangled and confusing, especially when they include more than just the branches you care about. Sound familiar? You need git show-branch.

I have a feature branch called stock-information on a project that’s hosted on Heroku. I want to compare it to my master branch and to the master branch on my staging remote:

git show-branch stock-information staging/master master

The output can be a little confusing at first, but once you learn how to read it it’s a huge time saver:

! [stock-information] WIP: Link to data series
 ! [staging/master] Add a description to Stock
  ! [master] Display Stocks
+   [stock-information] WIP: Link to data series
+   [stock-information~1] Create DataSeries for Stocks.
++  [staging/master] Add a description to Stock
++  [staging/master~1] Import external Stock information
+++ [master] Display Stocks

The first three lines are column headings. They show the commit at the tip of each of the branches I specified, with a ! to indicate which column will represent this branch in the lines that follow.

After the --- come the commits. The + characters near the start of the lines indicate which of the branches this commit is present on.

For example, the first commit only has a + in the first column. This lines up with the ! for stock-information in the heading section. So, we know that this commit is on the stock-information branch but not staging/master or master.

The third commit (“Add a description to Stock”) has a + in each of the first two columns, which indicates it is present on the stock-information and staging-master.

The output will end with the last commit that is present on all of the specified branches, indicated by a + in each of the leading columns.

What’s next?

If you found this useful, you might also enjoy:

Hound automatically reviews Ruby, JavaScript, and CoffeeScript code in your GitHub pull requests and comments on style violations. It is free for open source repos and $12/month per private repo.