< BACK TO BLOG

Git sort branches by date

Published Sun Feb 21 2021



Git sort branches by date

git for-each-ref --sort=-committerdate refs/heads/

# Or using git branch (since version 2.7.0)

git branch --sort=-committerdate # DESC

git branch --sort=committerdate # ASC

Advance usage

git for-each-ref --sort=committerdate refs/heads/ --format='%(HEAD) %(color:yellow)%(refname:short)%(color:reset) - %(color:red)%(objectname:short)%(color:reset) - %(contents:subject) - %(authorname) (%(color:green)%(committerdate:relative)%(color:reset))'

Ref -

https://stackoverflow.com/questions/5188320/how-can-i-get-a-list-of-git-branches-ordered-by-most-recent-commit




Subscribe to my Newsletter

Get the latest posts delivered right to your inbox