This is the reference for the commands that come up in real work — not the full man page. Grouped by what you're trying to do, with the flags that matter.
Starting and cloning
git init — create a new repo in the current folder
git clone <url> — clone a remote repo
git clone <url> --depth 1 — shallow clone, only latest commit (faster for CI)
Branching
git checkout -b feature-name — create and switch to a new branch
git switch -c feature-name — same as above (newer syntax)
git branch -d feature-name — delete a local branch (safe — won't delete unmerged)
git branch -D feature-name — force delete even if unmerged
git add -p — interactively stage chunks (best way to make clean commits)
git commit -m "message" — commit with inline message
git commit --amend --no-edit — add staged changes to last commit without changing message
git commit --amend -m "new message" — fix last commit message
Stashing
git stash — stash all uncommitted changes
git stash pop — apply most recent stash and remove it
git stash list — see all stashes
git stash apply stash@{2} — apply a specific stash without removing it
Undoing changes
git restore filename — discard unstaged changes to a file
git reset HEAD~1 — undo last commit, keep changes staged
git reset --hard HEAD~1 — undo last commit, discard changes
git revert HEAD — safe undo: new commit that reverses last commit
git reflog — view full history of HEAD changes (lifesaver after force-push)
Complete Developer Toolkit
This Git cheat sheet works best alongside our Git error guide — use the cheat sheet to find the right command and the error guide when something goes wrong. Our diff checker replicates git diff in the browser — paste two versions of a file to visualize what changed without needing a terminal. For automating git operations in CI/CD pipelines, our cron generator schedules automated git pulls or deployments, and our Linux terminal cheat sheet covers the shell commands that surround those git operations.
When reviewing pull requests that include config file changes, our JSON formatter validates modified package.json, tsconfig.json, or API config files. The regex tester helps you write git log --grep patterns and .gitignore glob expressions. For repos that include cron jobs in their deployment process, our crontab descriptor decodes those schedule expressions into plain English. Our SSL expiry checker and DNS lookup diagnose the connection issues that cause git push failures to remote repositories.
FAQ
Merge preserves history exactly as it happened — you get a merge commit and both branch histories. Rebase replays your commits on top of another branch, giving a linear history. Rebase is cleaner but rewrites commit hashes, so never rebase commits that others have already pulled.
Use reset for local commits you haven't pushed — it rewrites history. Use revert for commits you've already pushed — it creates a new commit that undoes changes without rewriting history, so it's safe to push.
git show <hash> shows the diff for a specific commit. git log --oneline --graph gives a visual branch history. git diff main..feature-branch shows all differences between two branches.