Last Updated: February 25, 2016
·
1.175K
· jwir3

Determine the health of git branches

In my current role, we typically use a git branch for each issue we're working on. This means we typically have a lot of branches lying around on our origin remote. When I asked some of the other developers when they decide to prune these branches down, the typical response was "A few weeks after I push the change up to master, but whenever I get around to it."

Given that there are a lot of branches on our origin remote, I thought, "Boy, wouldn't it be nice to see which branches are available, and the time they were last written to, all in one big list?"

Another pro tip on this issue, by @filipekiss, looks at this exact issue.<sup>1</sup>

But, it would be even better if I could say when I consider a branch to be "healthy" (i.e. last modified within X days), and only display the ones that aren't healthy.

So, I rewrote the original bash script in python. It's available here:
https://github.com/jwir3/proton-pack/tree/master/python

Installation is easy:

$ sudo python setup.py install

And using the script is even easier. Simply give it the number of days you want a branch to be considered 'healthy', with the '-d' parameter, and use '--bad-only' if you want it to only display branches that it considers to be 'old' (last modification time is greater than 2*<number of days a branch is considered to be 'healthy'>):

$ cd <my-git-repo>
$ git-branchhealth -d 14 --bad-only . 

Picture

It even orders them for you - the branches at the top are the ones that are the oldest. If you want to see all of your branches, don't use the '--bad-only' switch.

It's a little rough right now, but the script will get better over time. And, of course, patches are accepted. ;)