How view branches sorted by date in specific format and order - Git tricks(2)

View branch sorted by date

# sort desc (-committerdate)
git branch --sort=-committerdate

# sort asc (committerdate)
git branch --sort=-committerdate
git for-each-ref --sort='-committerdate' --format='%(refname)%09%(committerdate)' refs/heads
refs/heads/branch_name commitdate
refs/heads/branch_name2 commitdate

# real output
refs/heads/new_design Wed Apr 20 12:24:21 2022 +0200

refs/heads/design_assets Wed Apr 20 11:30:30 2022 +0200
git for-each-ref --sort='-committerdate' --format='%(refname)%09%(committerdate)' refs/heads | sed 's-refs/heads/--'

#output
branch_name commitdate
branch_name2 commitdate

#real output
new_design Wed Apr 20 12:24:21 2022 +0200

design_assets Wed Apr 20 11:30:30 2022 +0200

Note

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Abdlrahmansaber

Abdlrahmansaber

Software engineer, Problem solver, Geek.