Skip to content

Instantly share code, notes, and snippets.

@sunny
Created September 12, 2013 12:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sunny/6536434 to your computer and use it in GitHub Desktop.
Save sunny/6536434 to your computer and use it in GitHub Desktop.
Git branches ordered by freshness.
#!/bin/sh
# Via http://stackoverflow.com/a/18213567/311657
current_branch="$(git symbolic-ref --short -q HEAD)"
git for-each-ref --sort=committerdate refs/heads \
--format='%(refname:short)|%(objectname:short)|%(committerdate:relative)|%(authorname)|%(subject)|%(upstream:short)' \
| while IFS='|' read refname objectname date authorname subject upstream
do
reverse='\x1b[7m'
reset='\e[0m'
green='\e[32m'
red='\e[31m'
yellow='\e[33m'
blue='\e[34m'
cyan='\e[36m'
start=' '
if [[ $refname = $current_branch ]]; then
start='\x1b[7m* '
fi
printf "$cyan$start%-55s$reset $yellow%s $green%s $blue%s: $reset%s $cyan%s\\n" "$refname" "$objectname" "$authorname" "$date" "$subject" "$upstream"
done
@sunny
Copy link
Author

sunny commented Sep 12, 2013

Add this file in your ~/bin, then in your ~/.gitconfig aliases, add br = !git-br.

You can then:

$ git br

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment