Git Command Cheat Sheet
A searchable reference of common Git commands — branching, merging, remotes, history, undo, stash, and tags — with one-click copy.
| Category | Command | Description | |
|---|---|---|---|
Setup | git init | Create a new local repository | |
Setup | git clone <url> | Clone a remote repository | |
Basics | git status | Show working tree status | |
Basics | git add <file> | Stage a file for commit | |
Basics | git add -p | Interactively stage hunks | |
Basics | git commit -m "msg" | Commit staged changes | |
Basics | git commit --amend | Modify the last commit | |
Branching | git branch | List local branches | |
Branching | git branch <name> | Create a new branch | |
Branching | git switch <name> | Switch to a branch | |
Branching | git switch -c <name> | Create and switch to a new branch | |
Branching | git branch -d <name> | Delete a merged branch | |
Branching | git branch -D <name> | Force delete a branch | |
Merging | git merge <branch> | Merge a branch into the current one | |
Merging | git rebase <branch> | Reapply commits on top of another base | |
Merging | git rebase -i HEAD~n | Interactively rewrite the last n commits | |
Merging | git cherry-pick <sha> | Apply a specific commit onto the current branch | |
Remote | git remote -v | List remotes | |
Remote | git fetch | Download objects/refs without merging | |
Remote | git pull | Fetch and merge from a remote | |
Remote | git push | Upload local commits to a remote | |
Remote | git push -u origin <branch> | Push and set upstream tracking | |
History | git log --oneline | Compact commit history | |
History | git log --graph --all | Visualize branch history | |
History | git diff | Show unstaged changes | |
History | git diff --staged | Show staged changes | |
History | git blame <file> | Show who last changed each line | |
Undo | git restore <file> | Discard unstaged changes to a file | |
Undo | git restore --staged <file> | Unstage a file | |
Undo | git reset --soft HEAD~1 | Undo last commit, keep changes staged | |
Undo | git reset --hard HEAD~1 | Undo last commit and discard changes | |
Undo | git revert <sha> | Create a new commit that undoes a commit | |
Stash | git stash | Temporarily shelve changes | |
Stash | git stash pop | Reapply the most recent stash | |
Stash | git stash list | List all stashes | |
Tags | git tag <name> | Create a lightweight tag | |
Tags | git tag -a <name> -m "msg" | Create an annotated tag | |
Tags | git push --tags | Push all tags to remote |