Show git branches by date - useful for showing active branches

for k in `git branch|perl -pe s/^..//`;do echo -e `git show --pretty=format:"%Cgreen%ci %Cblue%cr%Creset" $k|head -n 1`\\t$k;done|sort -r
Print out list of all branches with last commit date to the branch, including relative time since commit and color coding.
Sample Output
2009-06-03 12:21:35 +0900 3 hours ago	add_cool_functionality
2009-06-02 16:15:13 +0900 24 hours ago	remove_strange_bug
2009-06-02 16:12:20 +0900 24 hours ago	implement_observer
2009-06-02 14:42:58 +0900 25 hours ago	experiment_with_bobcat_feature

By: brunost
2009-06-03 08:25:00

8 Alternatives + Submit Alt

What Others Think

Is there a good way to add that to the git alias?
youthenme · 544 weeks and 3 days ago
You can't add it as a git alias because it's using a bash for loop to run the command several times. What you can do is add a script at /usr/local/bin/git-branch-dates containing: #!/bin/bash for k in `git branch|perl -pe s/^..//`;do echo -e `git show --pretty=format:"%Cgreen%ci %Cblue%cr%Creset" $k|head -n 1`\\t$k;done|sort -r Git automatically searches through any bash scripts on your path that start with git- so you can now run: git branch-dates and the script will be run.
unixmonkey36469 · 433 weeks ago
Of course you can add it as a git alias! A git alias which is "!f() { ...bash script here...; }; f" works just fine. So, if you add an alias which says brel = "!f() { for k in `git branch|perl -pe s/^..//`;do echo -e `git show --pretty=format:'%Cgreen%ci %Cblue%cr%Creset' $k|head -n 1` \\\t$k; done | sort -r; }; f" git brel will do the proper thing. Of course, the single command git for-each-ref --sort=-committerdate --format='%1B[32m%(committerdate:iso8601) %1B[34m%(committerdate:relative) %1B[0;m%(refname:short)' refs/heads/ is easier to alias :)
mstormo · 394 weeks ago

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this? is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands

Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.


Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: