Skip to content

Instantly share code, notes, and snippets.

@dossy
Last active January 9, 2016 21:30
Show Gist options
  • Save dossy/6b49efd27ba2bdbbe0d8 to your computer and use it in GitHub Desktop.
Save dossy/6b49efd27ba2bdbbe0d8 to your computer and use it in GitHub Desktop.
Handy git tricks

Handy Git Tricks

Get branches, sorted by last commit

Local:

$ git for-each-ref --sort=-committerdate --format='%(committerdate:iso8601)  %(objectname:short)  %(refname)' refs/heads

Remote:

$ git for-each-ref --sort=-committerdate --format='%(committerdate:iso8601)  %(objectname:short)  %(refname)' refs/remotes/upstream

Merged branches

Local:

$ git branch --merged

Remote:

$ git branch -r --merged master upstream/\*
$ comm -12 <(git branch --merged | cut -c3-) <(git branch -r --merged master upstream/\* | cut -d/ -f2)

Merged remote branches, sorted by date of last commit:

$ for i in $(git branch -r --merged master upstream/\*); do git for-each-ref --format='%(committerdate:iso8601)  %(objectname:short)  %(refname)' refs/remotes/$i; done | sort -n
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment