Skip to content

Instantly share code, notes, and snippets.

@khalidchawtany
Last active August 29, 2015 14:16
Show Gist options
  • Save khalidchawtany/29c98f19c27b839a0927 to your computer and use it in GitHub Desktop.
Save khalidchawtany/29c98f19c27b839a0927 to your computer and use it in GitHub Desktop.
Git stuff that I forget all the time :)
#list branches
git branch #local branches
git branch -a #all branches
git branch -r #remote branches only
git branch -v #branches with latest commits
git branch -av #all branches with latest commits
#List branches by latest commit
git for-each-ref --sort=-committerdate refs/heads/
git for-each-ref --sort=-committerdate refs/heads/ --format='%(refname) %(committerdate) %(authorname)' | sed 's/refs\/heads\///g'
git for-each-ref --count=30 --sort=-committerdate refs/heads/ --format='%(refname:short)'
git for-each-ref --sort=-committerdate refs/heads/ --format='%(committerdate:short) %(authorname) %(refname:short)'
#colorfull list branches sorted by latest commit with info
for ref in $(git for-each-ref --sort=-committerdate --format="%(refname)" refs/heads/ refs/remotes ); do git log -n1 $ref --pretty=format:"%Cgreen%cr%Creset %C(yellow)%d%Creset %C(bold blue)<%an>%Creset%n" | cat ; done | awk '! a[$0]++'
alias glist='for ref in $(git for-each-ref --sort=-committerdate --format="%(refname)" refs/heads/ refs/remotes ); do git log -n1 $ref --pretty=format:"%Cgreen%cr%Creset %C(yellow)%d%Creset %C(bold blue)<%an>%Creset%n" | cat ; done | awk '"'! a["'$0'"]++'"
#Check out a pull request that is made local using [GetPRs](https://gist.github.com/khalidchawtany/6679fde46e23931365ed
git checkout pr/#####)
#get a diff of what is cahnged
git diff master Branch1 > ../patchfile
#__________OR_____________
git format-patch origin/master
#Get file names that are changed
git diff --name-only SHA1 SHA2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment