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 --listList all Git configuration
git config --global core.editor "code --wait"Set default editor to VS Code
Creating
git initInitialize 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 statusShow working tree status
git add <file>Stage a specific file
git add .Stage all changes
git add -pInteractively stage changes
git commit -m "message"Commit staged changes
git commit --amendAmend the last commit
git diffShow unstaged changes
git diff --stagedShow staged changes
Branching
git branchList local branches
git branch -aList 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 --abortAbort 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 stashStash current changes
git stash popApply and remove latest stash
git stash applyApply latest stash (keep in list)
git stash listList all stashes
git stash dropDelete latest stash
git stash push -m "message"Stash with a description
Inspecting
git logShow commit history
git log --onelineCompact commit history
git log --graph --oneline --allVisual branch graph
git show <commit>Show a specific commit
git blame <file>Show who changed each line
git reflogShow reference log (recovery)
Remote
git remote -vList remote repositories
git remote add origin <url>Add a remote
git fetchDownload remote changes
git pullFetch and merge remote changes
git pull --rebaseFetch and rebase remote changes
git pushPush commits to remote
git push -u origin <branch>Push and set upstream
git push --force-with-leaseSafe force push
Undoing Changes
git restore <file>Discard working tree changes
git restore --staged <file>Unstage a file
git reset HEAD~1Undo last commit (keep changes)
git reset --hard HEAD~1Undo last commit (discard changes)
git revert <commit>Create a commit that undoes another
git clean -fdRemove 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.