Where developers come to connect, share, build and be inspired.

59

Show git branches sorted by latest commit

3681 views

Note: coderwall's markdown pre-processor seems to think that -- indicate Haskell comments in the code blocks and is hiding them. I'm going to not use code blocks until it works. Sorry about that.

git config --global alias.latest "for-each-ref --sort=-committerdate --format='%(committerdate:short) %(refname:short)'"

Usage:

$ cd ~/Code/rails/rails && git latest

2012-11-19 origin/master
2012-11-19 origin/HEAD
2012-11-19 master
2012-11-19 origin/3-2-stable
2012-11-03 origin/encrypted_cookies
2012-11-03 origin/attributes_perf
... snipped ...

Show local branches only:

git config --global alias.latest "for-each-ref --sort=-committerdate refs/heads --format='%(committerdate:short) %(refname:short)'"

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

Comments

  • Blank-mugshot
    krainboltgreene

    By using committerdate:relative you can get:

    2 days ago master
    11 days ago origin/master
    5 weeks ago tokens-feature
    5 weeks ago origin/tokens-feature
    5 weeks ago origin/login-feature
    5 weeks ago login-feature
    6 weeks ago service-feature
    6 weeks ago origin/service-feature
    6 weeks ago identity-feature
    6 weeks ago origin/identity-feature
    6 weeks ago origin/accounts-feature
    6 weeks ago accounts-feature
    

  • Blank-mugshot
    pielgrzym

    Unfortunately for-each-ref's --format is crippled and you cannot use colors inside (in git log you can specify %C(yellow)string%C(reset)) :( anyone got around it maybe?

  • Thasmo-avatar.square_normal
    thasmo

    That would be cool to have it colored. Anyone?

  • Blank-mugshot
    fragphace

    To get colors use --shell option, like this:

    git for-each-ref --sort=-committerdate --shell --format='echo -e "\e[0031m" %(refname:short) "\e[00m\e[0032m" %(committerdate:relative) "\e[00m\e[0034m" %(committername) "\e[00m"' refs/heads/ refs/remotes | bash
    

Add a comment