Git Command Cheat Sheet

A searchable reference of common Git commands — branching, merging, remotes, history, undo, stash, and tags — with one-click copy.

CategoryCommandDescription
Setup
git initCreate a new local repository
Setup
git clone <url>Clone a remote repository
Basics
git statusShow working tree status
Basics
git add <file>Stage a file for commit
Basics
git add -pInteractively stage hunks
Basics
git commit -m "msg"Commit staged changes
Basics
git commit --amendModify the last commit
Branching
git branchList 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~nInteractively rewrite the last n commits
Merging
git cherry-pick <sha>Apply a specific commit onto the current branch
Remote
git remote -vList remotes
Remote
git fetchDownload objects/refs without merging
Remote
git pullFetch and merge from a remote
Remote
git pushUpload local commits to a remote
Remote
git push -u origin <branch>Push and set upstream tracking
History
git log --onelineCompact commit history
History
git log --graph --allVisualize branch history
History
git diffShow unstaged changes
History
git diff --stagedShow 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~1Undo last commit, keep changes staged
Undo
git reset --hard HEAD~1Undo last commit and discard changes
Undo
git revert <sha>Create a new commit that undoes a commit
Stash
git stashTemporarily shelve changes
Stash
git stash popReapply the most recent stash
Stash
git stash listList all stashes
Tags
git tag <name>Create a lightweight tag
Tags
git tag -a <name> -m "msg"Create an annotated tag
Tags
git push --tagsPush all tags to remote