The Practical Git Cheat Sheet
A clean, practical Git cheat sheet — the kind you actually use daily, not the 200-command monster nobody remembers. Organized by real-world workflow.
1. Setup & Config (One-time stuff)
git config --global user.name "Your Name"
git config --global user.email "your@email.com"
git config --global init.defaultBranch main
git config --list
2. Starting a Repository
Create new repo
git init
Clone existing repo
git clone <repo-url>
3. Daily Workflow (Most Used Commands)
Check status
git status
Add changes
git add file.txt
git add . # add everything
Commit
git commit -m "Your message"
See commit history
git log
git log --oneline --graph --decorate
4. Branching (Super Important)
Create branch
git branch feature-x
Switch branch
git checkout feature-x
# Modern way:
git switch feature-x
Create + switch
git checkout -b feature-x
# Modern way:
git switch -c feature-x
See branches
git branch
git branch -a
5. Merging
Merge branch into current
git merge feature-x
Rebase (cleaner history)
git rebase main
6. Remote (GitHub / GitLab Workflow)
Add remote
git remote add origin <repo-url>
See remotes
git remote -v
Push
git push origin main
git push -u origin main # set upstream
Pull latest
git pull
Fetch only
git fetch
7. Investigating Code
Who changed a line?
git blame file.js
Show commit details
git show <commit-hash>
See file changes
git diff
git diff file.js
8. Undo / Fix Mistakes (Very Important)
Unstage file
git restore --staged file.txt
Discard local changes
git restore file.txt
Reset last commit (keep changes)
git reset --soft HEAD~1
Reset last commit (remove changes)
git reset --hard HEAD~1
# WARNING: --hard deletes changes permanently.
9. Stashing (Temporary Save)
git stash
git stash list
git stash apply
git stash pop
10. Tags (Releases)
git tag v1.0
git tag
git push origin v1.0
11. Emergency Commands
Abort merge
git merge --abort
Abort rebase
git rebase --abort
See reflog (life saver)
git reflog
# If you mess up badly, git reflog can rescue you.
The 80/20 Rule (What You Actually Use Daily)
If you remember just these, you’re already 80% covered:
git statusgit addgit commitgit pushgit pullgit switch -cgit mergegit log --onelinegit reflog