Skip to content

Git Cheat Sheet

A copy+pasteable collection of common keyboard shortcuts, tips, and tricks for using Git .

--- Show git log -------------
git log --oneline
git log --oneline --abbrev-commit
git log --oneline --abbrev-commit --all
git log --oneline --abbrev-commit --all --graph
git log --oneline --abbrev-commit --all --graph --decorate
git log --oneline --abbrev-commit --all --graph --decorate --color

--- Discard unstaged changes ----------
git restore .                     <- all files
git checkout -- path/to/file.txt  <- specific file

--- Create and checkout a new branch ----------
git checkout -b mybranch

--- Switch branch -------------
git switch mybranch

--- Delete a branch ----------------------------
git branch --delete mybranch       <- local delete
git push origin --delete mybranch  <- remote delete
git remote prune origin            <- local references to remotes

--- Merge branch into main -------------
git switch main
git pull origin main
git merge mybranch
git push origin main

--- Merge main into branch -------------
git switch mybranch
git merge main

--- Git stash ------------------
git stash
git stash push -m "message"
git stash list
git stash apply            <- apply the latest stash
git stash apply stash@{n}  <- apply the stash at n
git stash pop              <- apply the latest stash, then delete it
git stash drop             <- remove the latest stash
git stash drop stash@{n}   <- remove stash at n

Want to sharpen your Git skills?
Check out our comprehensive Git problem set.