Cheat Sheet

Git Cheat Sheet — Complete Command Reference (Daily Use)

Practical Git cheat sheet covering everything from clone/commit to rebase, cherry-pick, bisect, and recovery. Free, bookmark-friendly, with real-world examples.

A practical Git reference — the commands you actually run, organized by what you're trying to do. Not every flag, just the ones that matter daily.

Setup & clone

CommandWhat it does
git config --global user.name "Name"Set commit author name globally
git config --global user.email "[email protected]"Set commit email globally
git config --global init.defaultBranch mainDefault new repos to main instead of master
git config --global pull.rebase trueAlways rebase instead of merge on pull
git clone <url>Clone a repo
git clone --depth 1 <url>Shallow clone (faster, only latest commit)
git initStart a new repo

Daily workflow

CommandWhat it does
git statusWhat's staged, what's modified, what's untracked
git status -sShort format (one line per file)
git add <file>Stage a file
git add -pStage hunks interactively (best for clean commits)
git add .Stage all changes in current directory
git diffShow unstaged changes
git diff --stagedShow staged changes
git diff mainCompare current branch to main
git commit -m "message"Commit staged changes
git commit -am "message"Stage all tracked files + commit
git commit --amendModify last commit (only if not pushed)
git commit --amend --no-editAdd staged changes to last commit, keep message

Branches

CommandWhat it does
git branchList local branches
git branch -aList local + remote branches
git branch <name>Create branch (don't switch)
git switch <name>Switch to branch (modern)
git switch -c <name>Create + switch (modern)
git checkout -b <name>Create + switch (legacy)
git branch -d <name>Delete branch (safe — refuses if unmerged)
git branch -D <name>Delete branch (force, even if unmerged)
git branch -m <old> <new>Rename branch
git branch --merged mainList branches already merged into main (safe to delete)

Sync with remote

CommandWhat it does
git fetchDownload remote changes (don't apply)
git fetch --pruneFetch + delete remote-tracking refs that no longer exist
git pullFetch + merge (or rebase if configured)
git pull --rebaseFetch + rebase (cleaner history)
git pushPush current branch to remote
git push -u origin <branch>First push of new branch (sets upstream)
git push --force-with-leaseForce push, but safer than --force
git remote -vList configured remotes
git remote add origin <url>Add a remote

Inspect history

CommandWhat it does
git logFull commit history
git log --onelineOne line per commit
git log --graph --oneline --allVisual branch graph (most useful)
git log -pShow diffs alongside log
git log -- <file>History of a specific file
git log --author="Alice"Filter by author
git log --since="2 weeks ago"Filter by time
git log --grep="bug"Filter by commit message
git show <commit>Show one commit's diff + metadata
git blame <file>Who last changed each line
git reflogLocal history of HEAD movements (recovery!)

Undo & recovery

CommandWhat it does
git restore <file>Discard unstaged changes (modern)
git restore --staged <file>Unstage a file (keep changes)
git checkout -- <file>Discard unstaged changes (legacy)
git reset HEAD <file>Unstage (legacy)
git reset --soft HEAD~1Undo last commit, keep changes staged
git reset --mixed HEAD~1Undo last commit, keep changes unstaged (default)
git reset --hard HEAD~1Discard last commit + changes (DESTRUCTIVE)
git revert <commit>Create a new commit that undoes the given commit (safe for shared branches)
git clean -nPreview untracked files that would be deleted
git clean -fdDelete untracked files + directories

Stash

CommandWhat it does
git stashSave uncommitted changes, return to clean working tree
git stash -uStash including untracked files
git stash listList stashes
git stash popApply most recent stash + remove from list
git stash applyApply most recent stash, keep in list
git stash dropDelete most recent stash

Rebase & cherry-pick

CommandWhat it does
git rebase mainReplay current branch's commits on top of main
git rebase -i HEAD~5Interactive rebase last 5 commits (squash, reorder, edit messages)
git rebase --continueAfter resolving conflicts, continue rebase
git rebase --abortCancel rebase, return to original state
git cherry-pick <commit>Apply a single commit from another branch
git cherry-pick <a>..<b>Apply a range of commits

Tags

CommandWhat it does
git tagList tags
git tag v1.0.0Create a lightweight tag
git tag -a v1.0.0 -m "Release 1.0"Create an annotated tag (recommended)
git push origin v1.0.0Push a single tag
git push --tagsPush all tags
git tag -d v1.0.0Delete tag locally

Search & debug

CommandWhat it does
git grep "pattern"Search tracked files (faster than grep)
git log -S "string"Find commits that added/removed a string ("pickaxe")
git log -G "regex"Find commits whose diff matches regex
git bisect startStart binary-search debugging
git bisect bad / good <commit>Mark commits during bisect
git bisect resetEnd bisect

Common scenarios

Oops, committed to wrong branch:

git reset HEAD~1 --soft
git stash
git checkout correct-branch
git stash pop
git commit

Pull failed because of local changes:

git stash
git pull
git stash pop

Recover a deleted branch:

git reflog                  # find the commit hash
git checkout -b restored <hash>

Squash last 3 commits:

git rebase -i HEAD~3
# In editor: change "pick" to "squash" for commits 2 and 3

Related tools

Comparing two text files line-by-line: diff checker. Verifying a downloaded file's SHA against a published hash: hash generator. Pretty-print API responses while debugging: JSON formatter.

Featured Tools

Try these free tools directly in your browser — no sign-up required.

git cheat sheet git commands git reference git rebase git revert git stash

Explore 300+ Free Tools

Utilko has tools for developers, writers, designers, students, and everyday users — all free, all browser-based.