Git Command Cheatsheet

The essential commands for everyday Git workflows

Setup & Init
git initInitialize a new repo
git clone <url>Clone a remote repo
git clone --depth 1 <url>Shallow clone (latest only)
git remote add origin <url>Link to remote
git remote -vShow remotes
git remote set-url origin <url>Change remote URL
Branching & Merging
git branchList local branches
git branch -aList all branches (incl. remote)
git branch <name>Create new branch
git checkout <branch>Switch to branch
git checkout -b <name>Create & switch to branch
git switch <branch>Switch branch (modern)
git switch -c <name>Create & switch (modern)
git merge <branch>Merge branch into current
git merge --no-ff <branch>Merge with merge commit
git rebase <branch>Rebase current onto branch
git branch -d <name>Delete merged branch
git branch -D <name>Force delete branch
git branch -m <old> <new>Rename branch
Staging & Status
git statusShow working tree status
git status -sShort status
git add <file>Stage a file
git add .Stage all changes
git add -pStage interactively (hunks)
git reset <file>Unstage a file
git diffShow unstaged changes
git diff --stagedShow staged changes
git diff <a> <b>Diff between two refs
Committing
git commit -m "msg"Commit with message
git commit -am "msg"Stage tracked + commit
git commit --amendAmend last commit
git commit --amend --no-editAmend without changing msg
git commit --allow-empty -m "msg"Empty commit (CI trigger)
git cherry-pick <sha>Apply specific commit
Remote & Sync
git fetchDownload remote changes
git fetch --pruneFetch & remove stale refs
git pullFetch + merge
git pull --rebaseFetch + rebase
git pushPush to remote
git push -u origin <branch>Push & set upstream
git push --force-with-leaseSafe force push
git push origin --delete <b>Delete remote branch
Undoing Changes
git checkout -- <file>Discard working changes
git restore <file>Discard changes (modern)
git restore --staged <file>Unstage (modern)
git reset --soft HEAD~1Undo commit, keep staged
git reset --mixed HEAD~1Undo commit, keep working
git reset --hard HEAD~1Undo commit, discard all
git revert <sha>Create undo commit
git clean -fdRemove untracked files/dirs
git reflogHistory of HEAD changes
Viewing History
git logFull commit log
git log --onelineCompact log
git log --oneline --graphLog with branch graph
git log -n 5Last 5 commits
git log --author="name"Filter by author
git log --since="2 weeks"Filter by date
git log -p <file>File change history
git log --statLog with file stats
git show <sha>Show commit details
git blame <file>Line-by-line authorship
git shortlog -snCommit count by author
Stashing
git stashStash working changes
git stash -uStash incl. untracked
git stash save "msg"Stash with description
git stash listList stashes
git stash popApply & remove latest stash
git stash applyApply without removing
git stash dropDelete latest stash
git stash clearDelete all stashes
Tags
git tagList tags
git tag v1.0.0Lightweight tag
git tag -a v1.0.0 -m "msg"Annotated tag
git push --tagsPush all tags
git tag -d v1.0.0Delete local tag
Configuration
git config --global user.name "X"Set name
git config --global user.email "X"Set email
git config --listShow all config
git config --global alias.co checkoutCreate alias
git config --global core.editor vimSet default editor
git config --global init.defaultBranch mainDefault branch name
ZeroKit.dev — Developer Cheatsheet Bundle