We finally got some breathing room on a Drupal project and the time came to clean up our branches. We have 8 developers on the project and about 240 branches. Now, I know a lot of people are going to immediately say, "That's way too many branches", but we do a branch per ticket to gain a more granular approach for picking and choosing what goes into a release. Ideally, these branches would be pruned after they are merged, but I think fear sometimes plays into not removing them, so days become weeks, weeks become months, and now we have 240 branches ;).
So anyway, I needed a way to break up the branches into manageable chunks to be dealt with. I started with 'git branch -r' which gave me all the branches, not very useful for dividing and conquering. I thought, "Why not just find who created the branch, and use that?", simple enough right? I couldn't find any easy way of finding the commit ID where the branch was created, so that option was out. Then I had a "poor man's House" moment. Why not just use the last commit author? They should have the most recent knowledge about the branch.
Now that I had a reasonable plan to categorize the branches, I wrote this quick script to print out just the data that I needed:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
#!/bin/sh # usage: # script-name -> list all branches and their author / last commit author # script-name 'author name' -> lists only branches by given author git branch -r | while read branch do name=`git log --pretty=tformat:%an -1 $branch` if [ $# -gt 0 ] && [ "$name" == "$1" ] then echo $branch : $name fi if [ $# -eq 0 ] then echo $branch : $name fi done
Now there might be an easier way to do this with the gits' tools (or maybe sed), but if you need a quick and dirty way to find all your git branch authors (or last commit author) this should work until someone smarter than me trumps it. Enjoy ;)