Skip to main content

Git Cheatsheet

Git is the backbone of modern version control. This cheatsheet organizes 25+ essential Git commands by workflow scenario — from your first commit to advanced branch surgery. Every command includes a practical example so you can use it immediately.

Updated: 2026-07-15·26 commands

Quick Reference by Task

What you want to doCommand
Start a new projectgit init / git clone
Save your workgit addgit commit
See what changedgit status / git diff / git log
Create a branchgit checkout -b / git switch -c
Merge branchesgit merge / git rebase
Undo a mistakegit revert / git reset
Pause your workgit stash
Sync with remotegit push / git pull

Setup(2)

CommandLevel
git init
Initialize a new Git repository
Basic
git clone
Clone a remote repository locally
Basic

Basic(5)

CommandLevel
git add
Stage changes for commit
Basic
git commit
Commit staged changes
Basic
git status
Show working tree status
Basic
git diff
Show changes between commits/working tree
Basic
git log
Show commit logs
Basic

Branch(5)

CommandLevel
git branch
List, create, or delete branches
Basic
git checkout -b
Create and switch to a new branch
Basic
git switch
Switch to an existing branch (modern way)
Intermediate
git merge
Merge a branch into the current branch
If conflicts occur, resolve then git add + git commit
Intermediate
git rebase
Reapply commits on top of another base
Never rebase branches that have been pushed
Expert

Stash(3)

CommandLevel
git stash
Temporarily save working directory changes
Intermediate
git stash pop
Restore and remove the last stash
Intermediate
git stash list
List all stashed changes
Intermediate

Undo(4)

CommandLevel
git reset --soft HEAD~1
Undo last commit, keep changes staged
If already pushed, use git revert instead
Intermediate
git reset --hard HEAD~1
Undo last commit, discard all changes (dangerous)
🔴 Irreversible! Discarded changes cannot be recovered
Expert
git revert
Create a new commit that undoes a previous commit
Intermediate
git restore
Discard uncommitted changes in working tree
Basic

Remote(4)

CommandLevel
git push
Push local commits to remote
Basic
git pull
Fetch and merge from remote
Basic
git fetch
Fetch latest data from remote (no auto-merge)
Intermediate
git remote -v
Show remote repositories
Basic

Advanced(3)

CommandLevel
git tag
List or create tags
Intermediate
git cherry-pick
Apply a specific commit to the current branch
Expert
git bisect
Binary search to find the commit that introduced a bug
Expert
This cheatsheet is compiled from official tool documentation. Last updated: 2026-07-15.