Git Cheatsheet

Searchable reference of common Git commands organized by category. Copy any command with one click.

Setup
git config --global user.name "Your Name"
Set your name for all repos
git config --global user.email "you@example.com"
Set your email for all repos
git config --list
List all Git configuration
git config --global core.editor "code --wait"
Set default editor to VS Code
Creating
git init
Initialize a new Git repository
git clone <url>
Clone a remote repository
git clone --depth 1 <url>
Shallow clone (latest commit only)
git clone --branch <branch> <url>
Clone a specific branch
Basic Changes
git status
Show working tree status
git add <file>
Stage a specific file
git add .
Stage all changes
git add -p
Interactively stage changes
git commit -m "message"
Commit staged changes
git commit --amend
Amend the last commit
git diff
Show unstaged changes
git diff --staged
Show staged changes
Branching
git branch
List local branches
git branch -a
List all branches (local + remote)
git branch <name>
Create a new branch
git checkout <branch>
Switch to a branch
git checkout -b <branch>
Create and switch to new branch
git switch <branch>
Switch to a branch (modern)
git switch -c <branch>
Create and switch (modern)
git branch -d <branch>
Delete a merged branch
git branch -D <branch>
Force delete a branch
Merging
git merge <branch>
Merge a branch into current
git merge --no-ff <branch>
Merge with a merge commit
git merge --abort
Abort a merge in progress
git rebase <branch>
Rebase current onto branch
git rebase -i HEAD~<n>
Interactive rebase last n commits
git cherry-pick <commit>
Apply a specific commit
Stashing
git stash
Stash current changes
git stash pop
Apply and remove latest stash
git stash apply
Apply latest stash (keep in list)
git stash list
List all stashes
git stash drop
Delete latest stash
git stash push -m "message"
Stash with a description
Inspecting
git log
Show commit history
git log --oneline
Compact commit history
git log --graph --oneline --all
Visual branch graph
git show <commit>
Show a specific commit
git blame <file>
Show who changed each line
git reflog
Show reference log (recovery)
Remote
git remote -v
List remote repositories
git remote add origin <url>
Add a remote
git fetch
Download remote changes
git pull
Fetch and merge remote changes
git pull --rebase
Fetch and rebase remote changes
git push
Push commits to remote
git push -u origin <branch>
Push and set upstream
git push --force-with-lease
Safe force push
Undoing Changes
git restore <file>
Discard working tree changes
git restore --staged <file>
Unstage a file
git reset HEAD~1
Undo last commit (keep changes)
git reset --hard HEAD~1
Undo last commit (discard changes)
git revert <commit>
Create a commit that undoes another
git clean -fd
Remove untracked files and dirs

Frequently Asked Questions

This cheatsheet covers the most commonly used Git commands organized by category. Git has hundreds of commands and flags — this is a curated reference for everyday development workflows including setup, branching, merging, stashing, and more.
Type any keyword in the search box to filter commands. It searches both the command syntax and its description. For example, searching 'branch' will show all branch-related commands across all categories.
Yes! Click the copy button next to any command to copy it to your clipboard. You can then paste it directly into your terminal.