Sort git branches by most recently modified

I sometimes forget the name of the git branch I was working on recently.

git branch -a lists all branches in alphabetical order by default. That is impractical if there are many branches.

This is where the --sort flag comes in handy. The following will sort branches by commit date in reverse chronological order.

git branch --sort=-committerdate

committerdate is the sort criterion. The minus indicates descending order.

This by itself can be hard to remember, but you can save the command in a shell alias. You can also set the default branch sort order with the branch.sort key in the git configuration.