Listing Git Branches In Order of Most Recent Commit
On a scale of 1-10, I'd say my "git fu" is maybe a 4 - with an occasional Google-search-fueled boost to a 5.5. I'm more than happy to stand on the shoulders of giants, though. Recently, while working on machina.js, I was transitioning from the v0.3.7 release back to my prep work for v0.4. I had several branches I'd used to play with v0.4 ideas, and couldn't remember which one I'd last left off with.
Then I came across this script:
git for-each-ref --sort=-committerdate refs/heads/ --format='%(refname:short)|%(committerdate:iso)|%(authorname)' | sed 's/refs\/heads\///g' | grep -v BACKUP | while IFS='|' read branch date author do printf '%-15s %-30s %s\n' "$branch" "$date" "$author" done
I created a bash script for it locally, and then aliased it in my
.zshrc as "branches". Now I get a nicely formatted output showing me the last committer and date per branch in order of most recent to oldest:
I highly recommend looking over some of the other approaches on that stack overflow thread. I learned a ton reading through them!