← til

Sorting git branches by the last commit date

June 12, 2020
git

I love hopping between branches with

git checkout -

but sometimes I work with more than two branches, and I forget the exact naming of the branch.

To find out the right name, I enter git branch and it outputs branches alphabetically sorted by default. This is never what I'm looking for, since I'm only interested in the branch that I was recently on.

Well, there's an option to sort them by the date of last commit on them:

git branch --sort=-committerdate

It's a good idea to use this as a default sort order:

git config --global branch.sort -committerdate
0 kudos