How to sort branches based on last activity?

git branch --sort=-committerdate --format="%(committerdate:relative)%09%(refname:short)"

To sort branches based on last activity use git branch --sort=-committerdate --format="%(committerdate:relative)%09%(refname:short)".

We recommend to create an alias for long commands like this. Originally by Aaron Patterson.

Layer 1
Terminal Example
git branch --sort=-committerdate --format="%(committerdate:relative)%09%(refname:short)"
2 days ago  alias-description
3 days ago  main
11 days ago quiz
2 weeks ago branches
3 weeks ago add-commands
3 weeks ago lazy-load-images
6 weeks ago try-different-fonts

git config --global alias.recent 'branch --sort=-committerdate --format="%(committerdate:relative)%09%(refname:short)"'

See git branch to learn more about it.

Last modified on November 30, 2021.

You might also like