The Git Cheat Sheet You'll Actually Use
Tired of googling Git commands you've used a hundred times before? This cheat sheet brings together the most useful Git commands for everyday development, from branching and commits to stashing and troubleshooting. Everything you need, nothing you don't.

Git is one of the most powerful tools in software development, but let's be honest: most of us use the same handful of commands every day and still find ourselves searching Stack Overflow for the syntax we forgot.
The good news? You don't need to memorize hundreds of Git commands to be productive. A small set of commands can cover the vast majority of your daily workflow while helping you avoid common mistakes.
Why a Git Cheat Sheet?
Even experienced developers occasionally forget command syntax or second-guess themselves before running a potentially destructive operation.
A good Git cheat sheet helps you:
Save time searching for commands
Avoid common Git mistakes
Work more confidently
Focus on writing code instead of remembering syntax
Keep your workflow consistent across projects
1. Check What's Happening
Before doing anything else:
git status
This command tells you:
Which files have changed
Which files are staged
Which files are untracked
Which branch you're on
If there's one Git command you should run constantly, it's this one.
2. Review Your Changes
See exactly what you've modified:
git diff
To see what you've already staged:
git diff --staged
Reviewing changes before committing prevents accidental commits and helps you catch mistakes early.
3. Work with Branches
Create a new branch and switch to it:
git switch -c feature/my-feature
Switch branches:
git switch main
See all local branches:
git branch
Delete an already merged branch:
git branch -d feature/my-feature
Branches are cheap. Use them often.
4. Save Your Work
Stage changes:
git add .
Create a commit:
git commit -m "Add new feature"
Need to fix your latest commit?
git commit --amend
A clear commit history will save future-you a lot of headaches.
5. Stay in Sync
Fetch changes without modifying your branch:
git fetch
Pull changes with a clean history:
git pull --rebase
Push your work:
git push
Push a new branch for the first time:
git push -u origin feature/my-feature
Using --rebase regularly helps keep commit history much cleaner.
6. Use Stash Like a Pro
Need to switch tasks without committing unfinished work?
Save everything:
git stash
Restore it later:
git stash pop
View saved stashes:
git stash list
This is a lifesaver when a teammate suddenly asks for help with something urgent.
7. Undo Mistakes Safely
Unstage a file:
git restore --staged file.txt
Discard local changes:
git restore file.txt
Undo your last commit but keep your changes:
git reset --soft HEAD~1
Completely remove the last commit and its changes:
git reset --hard HEAD~1
Use the hard reset carefully. It does exactly what it says.
8. Investigate the Past
View a compact history:
git log --oneline --graph --decorate --all
Find who changed a line:
git blame file.txt
Search commit messages:
git log --grep="ticket-123"
Find when specific code was added or removed:
git log -S "someText"
These commands are incredibly useful when debugging production issues.
9. Speed Things Up with Aliases
Configure once:
git config --global alias.lg "log --oneline --graph --decorate --all"
git config --global alias.st status
git config --global alias.co switch
git config --global alias.br branch
Then use:
git lg
git st
git co main
git br
Small time savings add up quickly over hundreds of commits.
10. The Git Golden Rule
Before every push:
git status
git diff --staged
git pull --rebase
git push
This simple sequence prevents most Git-related mistakes and keeps your local branch synchronized with your team.
Final Thoughts
Many developers treat Git as something they need to survive rather than a tool that can make them more productive. The reality is that mastering just a handful of commands can dramatically improve your workflow.
You don't need to know every Git command. You only need to know the ones you'll actually use.
Keep the cheat sheet nearby, practice these commands daily, and Git will start feeling less like a source of frustration and more like an extension of your development process.
Less memorizing. More building. 🚀
Gillade du inlägget?
Dela det med någon som också kan tycka det är intressant.
Relaterade inlägg

Getting Wi-Fi to work on an old Macbook Pro (Ubuntu)
Old Mac + Ubuntu = Wi-Fi struggle. 🐧💻 Every time I revive a 2011 Macbook Pro, the Broadcom drivers give me trouble. Here’s the 3-step fix to get the firmware-b43-installer working so you can stop tethering your phone and start surfing.
Support me on Ko-fi