Git Tricks

Git Aliases

git config --global alias.co checkout git config --global alias.br branch git config --global alias.ci commit git config --global alias.st status 

See also: More Aliases

Rewriting history

Rewrite last commit message

$ git commit --amend -m "new message" 

See also: Rewriting history

Branch

List all branches and their upstreams

$ git branch -vv 

Quickly switch to the previous branch

$ git checkout - 

Get only remote branches

$ git branch -r 

Checkout a single file from another branch

$ git checkout <branch> -- <file> 

Log

Search change by content

$ git log -S'<a term in the source>' 

Show changes over time for specific file

$ git log -p <file\_name> 

Print out a cool visualization of your log

$ git log --pretty=oneline --graph --decorate --all 

Rename branch

  • #### #Renamed to new_name
$ git branch -m <new\_name> 
  • #### #Push and reset
$ git push origin -u <new\_name> 
  • #### #Delete remote branch
$ git push origin --delete <old> 
Comments