Git Cheatsheet
Sections
7
categories
Commands
52
total
Visible
52
all
Engine
git
v2.x
commands
Setup & config
git --versiongit config --global user.name "You"git config --global user.email you@xgit config --global init.defaultBranch maingit initgit clone <url>git clone --depth 1 <url>Staging & committing
git statusgit add <file>git add -pgit reset <file>git commit -m "msg"git commit --amendgit rm <file>git mv <a> <b>Branching
git branchgit branch -agit branch -d <name>git switch <branch>git switch -c <name>git merge <branch>git merge --abortgit rebase <branch>git rebase -i HEAD~3git rebase --continueRemote
git remote -vgit remote add <name> <url>git fetch --all --prunegit pull --rebasegit push -u origin <branch>git push --force-with-leasegit push --tagsInspection
git log --oneline --graph --decorategit log --author=namegit show <sha>git diffgit diff --stagedgit blame <file>git shortlog -snUndoing
git restore <file>git restore --staged <file>git reset --soft HEAD~1git reset --hard HEAD~1git revert <sha>git clean -fdStash & tags
git stashgit stash popgit tag -a v1.0.0 -m msggit push origin v1.0.0git cherry-pick <sha>git refloggit worktree add <path> <branch>meaning
Setup & config
Show installed Git version
Set committer name
Set committer email
Default new repos to main
Initialize a new repo
Clone a remote repository
git clone git@github.com:o/r.git
Shallow clone (latest commit only)
Staging & committing
Show working tree status
Stage specific file
Stage hunks interactively
Unstage file (keep changes)
Commit staged changes
Modify last commit
Remove file from index and disk
Move/rename a tracked file
Branching
List local branches
List all incl. remotes
Delete branch (safe)
Modern: switch branches
Modern: create + switch
Merge branch into current
Abort an in-progress merge
Rebase current onto branch
Interactive rebase last 3
Continue rebase after conflicts
Remote
List remote URLs
Add a remote
Fetch all + prune deleted
Fetch + rebase onto upstream
Push and set upstream
Safer force-push
Push local tags to remote
Inspection
Compact graph view
Filter log by author
Show details of a commit
Unstaged changes
Staged changes vs HEAD
Show who changed each line
Commit count per author
Undoing
Discard unstaged changes
Unstage file
Undo last commit, keep staged
Discard last commit entirely
Create commit that reverses <sha>
Remove untracked files & dirs
Stash & tags
Stash dirty working tree
Apply + drop latest stash
Create annotated tag
Push a single tag
Apply commit from another branch
Show ref history (recover lost commits)
Branch into separate dir