Git: List git branches, sort by (and show) date

GitListSortingDateBranch

Git Problem Overview


How can I list git branches showing and sorting by their last commits' dates?

I've found this:

for k in `git branch | sed s/^..//`; do
    echo -e `git log -1 --pretty=format:"%Cgreen%ci %Cblue%cr%Creset" "$k"`\\t"$k";
done | sort -r

I'd expect plain git to have this feature. Does it?

I also found git show-branch --date-order but the output is something different.

Git Solutions


Solution 1 - Git

This appears to be a built-in way to achieve that (v1.7.4):

git for-each-ref --sort=committerdate refs/heads/ --format='%(committerdate:short) %(refname:short)'

Solution 2 - Git

I've enjoyed the @Will Sheppard solution to put some colors.

git for-each-ref --sort=committerdate refs/heads/ --format='%(color: red)%(committerdate:short) %(color: cyan)%(refname:short)'

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionOndra ŽižkaView Question on Stackoverflow
Solution 1 - GitWill SheppardView Answer on Stackoverflow
Solution 2 - GitJmLavoierView Answer on Stackoverflow