Git Commands Cheat Sheet
A printable Git reference covering setup, workflow, branching, history, undo, and remote operations. Keep it by your desk for quick lookups.
Git Commands Reference
printablepolly.com
Setup
git initInitialize a new repository
git clone <url>Clone a remote repository
git config user.name "Name"Set commit author name
git config user.email "email"Set commit author email
Basic Workflow
git statusShow working tree status(-s (short))
git add <file>Stage file(s) for commit(-A (all), -p (patch))
git commit -m "msg"Commit staged changes(--amend, -a (add tracked))
git pushPush commits to remote(-u origin <branch>)
git pullFetch and merge from remote(--rebase)
git diffShow unstaged changes(--staged, --stat)
Branching
git branchList branches(-a (all), -d (delete))
git checkout <branch>Switch to branch(-b (create & switch))
git switch <branch>Switch branches (modern)(-c (create))
git merge <branch>Merge branch into current(--no-ff, --squash)
git rebase <branch>Rebase current onto branch(--interactive, --abort)
History
git logShow commit history(--oneline, --graph, -n)
git blame <file>Show who changed each line
git show <commit>Show commit details
git log --follow <file>History for a specific file
Undo
git reset <file>Unstage a file(--hard (discard all))
git revert <commit>Create undo commit
git stashTemporarily save changes(pop, list, drop)
git checkout -- <file>Discard file changes
git restore <file>Discard changes (modern)(--staged (unstage))
Remote
git fetchDownload remote changes(--all, --prune)
git remote -vList remote URLs
git remote add <name> <url>Add a remote
git push -u origin <branch>Push & track branch
git pull --rebasePull with rebase (cleaner history)
Related Templates
FAQ
What is the difference between git pull and git fetch?
git fetch downloads changes from the remote but doesn't merge them. git pull does a fetch followed by a merge (or rebase with --rebase flag). Fetch is safer for reviewing changes before integrating.
How do I undo my last commit without losing changes?
Use 'git reset --soft HEAD~1' to undo the commit but keep changes staged, or 'git reset HEAD~1' to undo and unstage. Use --hard only if you want to discard changes entirely.
What is the difference between merge and rebase?
Merge creates a merge commit preserving branch history. Rebase replays your commits on top of the target branch for a linear history. Use merge for shared branches; rebase for local/feature branches before merging.