Found this helpful?
Share it with other developers
Git Commands Cheat Sheet: Never Get Lost Again
Stop Googling Git commands every 5 minutes. This interactive cheat sheet covers everything from basic commits to advanced workflows - with examples you can try right here.
😤 We've All Been There
"How do I undo that commit?"
"What's the difference between merge and rebase?"
"I accidentally committed to main instead of my feature branch!"
"My Git history is a mess... again."
Sound familiar? You're not alone. Even experienced developers struggle with Git's 150+ commands.
✨ The Solution: Master The Core 20
You don't need to memorize every Git command. Master these 20 commands and you'll handle 95% of real-world scenarios. Try this interactive Git simulator:
Interactive Git Simulator
Practice Git commands • Safe sandbox environmentLearn Git workflows without fear of breaking anything
🎯 Perfect! Practice Git commands risk-free before using them on real projects.
📚 Essential Commands by Category
1Repository Setup
git initInitialize new repository
Creates .git folder in current directory
git clone <url>Copy remote repository
Downloads entire project history
git remote add origin <url>Connect to remote repository
Usually GitHub, GitLab, or Bitbucket
2Basic Workflow (The Daily Grind)
git statusCheck current state
Shows modified, staged, and untracked files
git add .Stage all changes
Use git add <file> for specific files
git commit -m "message"Save staged changes
Write clear, descriptive messages
git pushUpload to remote
First time: git push -u origin main
git pullDownload latest changes
Combines fetch + merge
3Branching (Your Safety Net)
git branchList all branches
* marks current branch
git branch <name>Create new branch
Doesn't switch to it automatically
git checkout <branch>Switch to branch
Use git switch <branch> in newer Git
git checkout -b <name>Create and switch
Combines branch creation + checkout
git branch -d <name>Delete branch
Use -D to force delete
4Merging (Bringing It Together)
git merge <branch>Merge branch into current
Creates a merge commit
git rebase <branch>Reapply commits on top
Cleaner history, but rewrites commits
git merge --no-ff <branch>Force merge commit
Preserves branch history even for fast-forwards
🚨 Troubleshooting: When Things Go Wrong
❌ "I need to undo my last commit"
⚠️ --hard permanently deletes changes!
🔄 "I committed to the wrong branch"
💡 Cherry-pick copies the commit to target branch
⚔️ "I have merge conflicts"
💡 Look for <<<<<<< markers in conflicted files
↩️ "I want to discard local changes"
⚠️ This permanently deletes uncommitted changes
🔄 Common Workflows
🌟 Feature Branch Workflow
🚨 Hotfix Workflow
💡 Pro Tips
✅ Best Practices
- ✓ Commit early, commit often
- ✓ Write clear commit messages
- ✓ Pull before pushing
- ✓ Use branches for features
- ✓ Review changes before committing
⚠️ Watch Out For
- ⚠️ Never rebase shared branches
- ⚠️ Don't commit secrets/passwords
- ⚠️ Avoid huge commits
- ⚠️ Don't force push to main
- ⚠️ Test before committing
🎯 Useful Aliases
Add these to your ~/.gitconfig for faster commands:
📊 Git Flow Visualization
🌳 How Git Branches Actually Work
A, B, C: Initial commits on main
D, E: Feature development on branch
F: Merge commit bringing feature back
G: New commit on main after merge
Each commit is a snapshot of your entire project. Branches are just moveable pointers to commits.
Mind = Blown?
This quick tutorial was just a taste. Want to see the full power of interactive learning? Check out our complete deep-dive into how we built this entire blog with embedded code execution.
Stop Copy-Pasting. Run Code Where You Read It.
The complete story of building the world's first interactive developer blog
Never Miss an Interactive Tutorial
Get new hands-on tutorials delivered weekly. Each one includes live code you can run instantly—no copy-pasting required.
Continue Your Learning Journey
Docker Commands Cheat Sheet: From Beginner to Pro
Master Docker with essential commands, best practices, and real-world examples.
Linux Commands Every Developer Should Know
Essential Linux commands with practical examples for developers and DevOps.
GitHub Actions: Complete CI/CD Guide
Automate your development workflow with GitHub Actions. Step-by-step examples.
Advanced Git Techniques: Interactive Rebase & More
Master advanced Git features like interactive rebase, hooks, and custom workflows.