Skip to content

Instantly share code, notes, and snippets.

@andou
Last active March 17, 2025 03:38
Show Gist options
  • Save andou/5598810 to your computer and use it in GitHub Desktop.
Save andou/5598810 to your computer and use it in GitHub Desktop.
Cheat-sheet shorthand practical guide to Git
alias glf='git log --simplify-by-decoration --oneline --decorate --name-status'
alias gl='git log --simplify-by-decoration --oneline --decorate'
alias glf='git log --simplify-by-decoration --oneline --decorate --name-status'
alias gll='git log'
alias gs='git status -s -b'
alias gss='git status'
alias ga='git add'
alias gcm='git commit'
alias gc='git checkout'
alias gpl='git pull origin'
alias gps='git push origin'

List branches, -v shows last commit comment

$ git branch [-v]

Create a new branch. Remind where you branch from!!

$ git checkout -b <branch>

To delete a local unmerged branch

$ git branch -D <branch>

Show branches containing a specific commit

$ git branch --contains <sha1>

To delete a local merged branch

$ git branch -d <branch>

To delete a remote branch

$ git push origin --delete <branch>
$ git push origin :<branch>

Showing differences on a file between two branches(usally master and feature)

$ git diff <branch1>:path/to/file/ <branch2>:path/to/file/

Showing files differences between branches(usually master and feature prior to merge)

$ git diff --stat --color <branc1h>..<branch2>

Showing unpushed modifications

$ git diff origin/<branch>..HEAD

Ninja version

$ git log --branches --not --remotes --simplify-by-decoration --decorate --oneline

Show commits on current branch

$ git log

Show commits on another branch

$ git log <branch>

Show commits and modified files on current branch

$ git log --name-status

Show commits of a specific author

$ git log --author <author>

Show commits and graph branches dependecies on current branch

$ git log --graph

Nice graphical diff between two branches (usually master and feature)

$ git log --left-right --graph --cherry-pick <branch1>...<branch2>

Show upushed commits

$ git log origin/<branch>..HEAD

Reverting an unwanted commit

$ git revert <sha1>

Cherry pick of a commit on top of current branch

$ git cherry-pick <sha1>

Final solution when you mess all up, before pushing

$ git reset --hard origin/<branch>

Getting rid of unwanted files, expression example: .DS_Store

$ find . -name <expression> -print0 | xargs -0 git rm --ignore-unmatch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment