List recent git branches
Ever forget which branch you were working on? Here's a little snippet to list the most recent git branches by commit date.
Add this to your ~/.gitconfig*
[alias] recent-branches = !git for-each-ref --sort='-committerdate' --format='%(committerdate)%09%(objectname:short)%09%(refname)' refs/heads | sed -e 's,refs/heads/,,' | head
Usage:
git recent-branches -n 5 Wed Oct 30 14:59:58 2019 -0700 fd658fd master Wed Oct 30 14:57:05 2019 -0700 8a4c5a4 feature/docker-unit-tests Wed Oct 30 13:19:45 2019 -0700 783ae60 feature/increase-num-threads Tue Oct 29 16:06:40 2019 -0700 ac3c9d2 bugfix/hash-collisions Tue Oct 29 15:33:51 2019 -0700 f2c1ab1 feature/wip
Command line:
Can also just commands on the command line
git for-each-ref --sort='-committerdate' --format='%(committerdate)%09%(objectname:short)%09%(refname)' refs/heads | sed -e 's,refs/heads/,,' | head
In case you're wondering the %09 is a tab character in the git for-each-ref formatting.
References:
https://davidwalsh.name/sort-git-branches
https://git-scm.com/docs/git-for-each-ref












