Skip to content

Instantly share code, notes, and snippets.

@igorescobar
Created February 7, 2013 12:44
Show Gist options
  • Save igorescobar/4730672 to your computer and use it in GitHub Desktop.
Save igorescobar/4730672 to your computer and use it in GitHub Desktop.
Git Branches Sorted by Last Commit
So you've got the cluttered branch list that we talked about before; some of those you've cleaned up with the --merged flag. But what about all those other branches? How do you know which ones are useful or entirely out of date? The for-each-ref command will output a list for each branch and show the reference information for the last commit. We can customize the output to include some useful information, but, more importantly, we can sort the list by date. This command will give us a list of branches with the last commit message and committer, sorted in descending date order. (via Rein Henrichs)
git for-each-ref --sort=-committerdate --format='%(committerdate:short) %(refname:short) [%(committername)]'
While you could type this command each time, I highly recommend making it an alias and save yourself some serious headaches.
git config --global alias.latest "for-each-ref --sort=-committerdate --format='%(c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment