Show all git branches, ordered by date

By default, “git branch -a” shows you both local and remote branches for your repository. Wondering when each branch was worked on last? It’s a bit hard, especially that git makes 2 piles of branches – the local ones and the remote ones separately. To see them ordered by when they were worked on last, just use :

   for k in `git branch -a|perl -pe s/^..//`;do echo -e `git show --pretty=format:"%Cgreen%ci %Cblue%cr%Creset" $k|head -n 1`\\t$k;done|sort -r

If you’re like me and use this a lot, make it a function and add it as an alias to your .bashrc/.zshrc/.whateverrc

function gitbr {
   for k in `git branch -a|perl -pe s/^..//`;do echo -e `git show --pretty=format:"%Cgreen%ci %Cblue%cr%Creset" $k|head -n 1`\\t$k;done|sort -r
}
alias gitbr=gitbr