Viewing Aging Git Branches

This really simple shell script from my friend, Robb Kidd, system administrator extraordinaire, shows git branches in order based on their most recent check-in date. You'd be surprised how useful this script is.

As a developer, you may be working on multiple bug fixes, plus longer-term development tasks, at the same time on a particular project. With git as your source code repository, it's common for developers to work on each fix or task in a different branch.

But then you have to remember those branch names, and which branches you worked in most recently.

The aging script creates a simple "report" showing all branches, in order based on how recently changes have been checked in. It also shows who committed the most recent check-in.

Here's the script:


git branch -a | grep -v HEAD | sed s/^..// | while read branch; do
  echo `git log -1
    --pretty=format:"%Cgreen%ci %Creset%h %Cblue%cr%Creset (%cn)" $branch`
    $branch ; 
done | sort

Note that the code has been tidied up for display. The two indented lines after the "echo" line should actually be on the same line.

The output looks like this:

2012-07-10 16:37:34 -0400 0e3ac28 11 days ago (David Keener) remotes/origin/breadcrumbs_fix
2012-07-11 11:25:42 -0400 57338ee 10 days ago (Chad Fowler) remotes/origin/fix_elevated_alarm
2012-07-12 13:47:56 -0400 c3e3df0 9 days ago (Jim Wierich) remotes/origin/disableNegativity
2012-07-12 15:25:38 -0400 270537c 9 days ago (Rich Kilmer) remotes/origin/updateXMLFile
2012-07-12 16:24:39 -0400 8ce5787 9 days ago (Yehuda Katz) remotes/origin/master
2012-07-13 10:28:13 -0400 9d56685 8 days ago (Yehuda Katz) remotes/origin/dns_error
2012-07-13 10:50:02 -0400 61525d5 8 days ago (Chad Fowler) remotes/origin/XYZ_fix
2012-07-16 12:07:39 -0400 d835f8d 5 days ago (David Keener) remotes/origin/search_widget_upgrade


No comments yet. Be the first.

Leave a Comment

Comments are moderated and will not appear on the site until reviewed.

(not displayed)