Git Quick Cheat Sheet

git cheatsheet command

Fast lookup for the commands you actually use. Replace placeholders like <file>, <branch>, <name>, and <commit>.


Quick Index


Status / Inspect

CommandWhat it does
git statusWhat changed + what’s staged.
git diffUnstaged changes.
git diff --stagedStaged changes (not committed).
git log --oneline --decorate --graph -n 20Quick recent history graph.

Stage / Commit

CommandWhat it does
git add <file>Stage file.
git add .Stage all changes.
git commit -m "msg"Commit staged changes.
git commit --amendFix last commit (only if not pushed).
git reset <file>Unstage file (keeps edits).

Branches

CommandWhat it does
git branchList branches.
git checkout -b <name>New branch + switch (classic).
git checkout <name>Switch branch (classic).
git switch -c <name>New branch + switch (modern).
git switch <name>Switch branch (modern).
git merge <name>Merge <name> into current branch.

Remotes

CommandWhat it does
git remote -vShow remotes.
git fetch originDownload remote updates only.
git pull origin <branch>Fetch + merge.
git push origin <branch>Push branch.
git push -u origin <branch>Push + set upstream tracking.

Undo / Park Work

TaskCommand
Revert a commit safely (works after push)git revert <commit>
Hard reset to a commit (danger)git reset --hard <commit>
Stash workgit stash
Stash including untrackedgit stash -u
Re-apply stashgit stash pop

Rule of thumb: If it is already pushed, prefer revert over reset --hard.


Create / Clone

CommandWhat it does
git clone <url>Clone repo.
git initInit repo in folder.

Do this a lot workflows

New repo: first push to main

git init
git add .
git commit -m "Initial commit"
git branch -M main
git remote add origin <repo_url>
git push -u origin main

Feature branch and push

git checkout -b feature/my-change
# work...
git add .
git commit -m "My change"
git push -u origin feature/my-change

Update your feature branch with latest main (merge)

git checkout main
git pull origin main
git checkout feature/my-change
git merge main

Help

git help <command>