Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 713
Ondra Žižka Avatar asked Feb 10 '12 23:02

Ondra Žižka


People also ask

How can I get a list of git branches ordered by most recent commit?

Use git branch --sort=-committerdate to display a list of all local branches and sort them based on the date of their last commit. Use arrow keys to navigate, press Q to exit.

How can you tell if two branches are identical?

In order to compare two branches easily, you have to use the “git diff” command and provide the branch names separated by dots. Using this command, Git will compare the tip of both branches (also called the HEAD) and display a “diff” recap that you can use to see modifications.

What is the date command to view all the remote branches?

Command #1: git branch -r This Git command will show you remote branches.


2 Answers

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)'
like image 133
Will Sheppard Avatar answered Nov 16 '22 01:11

Will Sheppard


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)'
like image 27
JmLavoier Avatar answered Nov 16 '22 01:11

JmLavoier