🚀 7 Git Commands Every Developer Should Know (But Most Don't)
If your Git workflow still looks like this...
git add .
git commit -m "fix"
git push
...you're leaving a lot of productivity on the table.
After working with Git every day for years, I realized that most developers only use about 20% of what Git can actually do.
Here are 7 Git commands that can save hours of debugging, make collaboration easier, and help you recover from mistakes like a pro.
1. git reflog — Your Git Time Machine 🕒
Have you ever accidentally deleted a branch, reset your commits, or messed something up?
Don't panic.
git reflog
This command shows every movement of your HEAD, including commits that don't even appear in your Git history anymore.
Example:
git reflog
Output:
a4b12cd HEAD@{0}: reset: moving to HEAD~1
7d9ef12 HEAD@{1}: commit: Added authentication
Recover it instantly:
git reset --hard HEAD@{1}
💡 Pro Tip: Before saying "I lost my code!", run git reflog.
It has saved countless developers more times than they'll admit.
2. git bisect — Find the Bug Automatically 🔍
Imagine your application worked yesterday.
Today?
Everything is broken.
Instead of checking 50 commits manually:
git bisect start
git bisect bad
git bisect good <last-working-commit>
Git will perform a binary search through your history.
After testing each suggested commit:
git bisect good
or
git bisect bad
Git keeps narrowing it down until it finds the exact commit that introduced the bug.
This turns:
"Let's check hundreds of commits..."
into
"Git found the problem in minutes."
3. git stash — Pause Your Work Without Committing 📦
You're halfway through a feature.
Suddenly:
"Can you quickly fix production?"
Instead of creating a messy WIP commit:
git stash
Switch branches.
Fix the issue.
Come back.
Restore everything:
git stash pop
Need multiple stashes?
git stash list
Preview changes:
git stash show -p
This command keeps your commit history clean while letting you multitask safely.
4. git cherry-pick — Copy One Commit, Not the Entire Branch 🍒
Suppose you fixed a bug on another branch.
Instead of merging everything:
git cherry-pick <commit-hash>
Git copies only that specific commit.
Perfect for:
- Hotfixes
- Production patches
- Backporting fixes
- Reusing code across release branches
It's one of the cleanest ways to move changes around.
5. git blame — Find Who Changed That Line 👀
Need to know who introduced a specific line?
git blame app.js
Output:
8c42f1d (Alex 2026-06-01) const apiUrl = ...
You'll see:
- Author
- Commit
- Date
- Exact line
This isn't about blaming teammates.
It's about understanding the context before changing code.
Most of the time you'll discover...
It was actually your own code from six months ago. 😅
6. git log --oneline --graph --all — Visualize Your Repository 🌳
Instead of reading endless commit history:
git log --oneline --graph --all
You'll get something like:
* 8ad32 Fix login bug
|\
| * 7bd21 Add dashboard
|/
* 91cd1 Initial commit
This helps you understand:
- Branch structure
- Merge history
- Feature branches
- Commit relationships
Especially useful when joining an unfamiliar project.
7. git restore — Undo Changes Without Losing Everything 🔄
Made changes you don't want?
Restore a file:
git restore index.js
Unstage files:
git restore --staged index.js
This is much safer than using confusing checkout commands.
Modern Git recommends restore because it's more explicit and easier to understand.
Bonus: The Command I Use Almost Every Day ⭐
git log --oneline --decorate --graph --all
It gives a beautiful overview of the repository with branch names and tags.
Once you start using it, it's hard to go back.
Quick Cheat Sheet
| Command | Purpose |
|---|---|
git reflog |
Recover lost commits |
git bisect |
Find the commit that introduced a bug |
git stash |
Save work temporarily |
git cherry-pick |
Copy a single commit |
git blame |
See who changed a line |
git log --oneline --graph --all |
Visualize history |
git restore |
Undo changes safely |
Final Thoughts
Git isn't just about commit and push.
The more you understand Git, the less time you'll spend fixing mistakes and the more confident you'll become when working on large codebases.
These commands have saved me countless hours while debugging production issues, reviewing code, and collaborating with teams.
If you're serious about becoming a better developer, start using at least one new Git command this week.
Your future self will thank you.
💬 Which Git command do you use the most?
Or share a hidden Git trick that every developer should know.
I'd love to learn something new from the community. 🚀
👋 Thanks for Reading!
Hi, I'm Darshan Raval — a Technology Lead and Node.js Developer with 7+ years of experience building scalable backend systems, microservices, and real-time applications.
I enjoy sharing practical tips on Node.js, JavaScript, System Design, Git, AI, Backend Development, and everything that helps developers write better code and grow in their careers.
If you found this article helpful, consider:
- ❤️ Leaving a reaction
- 💬 Sharing your favorite Git command in the comments
- 🔖 Following me for more developer-focused content every week
Happy Coding! 🚀
Top comments (0)