The git commands developers run all day, plus the recovery moves for when things go wrong. Accurate, copy-paste-ready syntax.
git initCreate a new repo in the current directory.git clone <url>Copy a remote repo locally.git statusShow staged, unstaged, and untracked changes.git add <file>Stage changes; git add . stages everything.git commit -m "msg"Record staged changes with a message.git log --onelineCompact commit history, one line each.git branchList branches; add a name to create one.git switch <branch>Move to an existing branch (modern alias for checkout).git switch -c <branch>Create and switch to a new branch.git merge <branch>Merge another branch into the current one.git rebase <branch>Replay your commits on top of another branch.git branch -d <branch>Delete a merged branch (-D to force).git remote -vList configured remotes and their URLs.git fetchDownload remote changes without merging.git pullFetch and merge remote changes into the current branch.git pushUpload commits; -u origin <branch> sets upstream.git push --force-with-leaseSafely overwrite a remote branch after a rebase.git restore <file>Discard unstaged changes in a file.git restore --staged <file>Unstage a file, keeping changes.git commit --amendEdit the most recent commit or its message.git reset --soft HEAD~1Undo last commit, keep changes staged.git reset --hard HEAD~1Undo last commit and discard changes (careful!).git revert <hash>Create a new commit that undoes a past one.git reflogShow every HEAD move; recover "lost" commits.git stashShelve uncommitted changes; git stash pop restores them.git stash listShow all stashes.git diffShow unstaged changes; --staged for staged ones.git blame <file>Show who last changed each line.git cherry-pick <hash>Apply a single commit from another branch.Want ready-to-use prompts to go with this cheatsheet?
Browse 30,000+ Prompts