π 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
Enter fullscreen mode Exit fullscreen mode
…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
Enter fullscreen mode Exit fullscreen mode
This command shows every movement of your HEAD, including commits that don’t even appear in your Git history anymore.
Example:
git reflog
Enter fullscreen mode Exit fullscreen mode
Output:
a4b12cd HEAD@{0}: reset: moving to HEAD~1
7d9ef12 HEAD@{1}: commit: Added authentication
Enter fullscreen mode Exit fullscreen mode
Recover it instantly:
git reset --hard HEAD@{1}
Enter fullscreen mode Exit fullscreen mode
π‘ 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>
Enter fullscreen mode Exit fullscreen mode
Git will perform a binary search through your history.
After testing each suggested commit:
git bisect good
Enter fullscreen mode Exit fullscreen mode
or
git bisect bad
Enter fullscreen mode Exit fullscreen mode
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
Enter fullscreen mode Exit fullscreen mode
Switch branches.
Fix the issue.
Come back.
Restore everything:
git stash pop
Enter fullscreen mode Exit fullscreen mode
Need multiple stashes?
git stash list
Enter fullscreen mode Exit fullscreen mode
Preview changes:
git stash show -p
Enter fullscreen mode Exit fullscreen mode
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>
Enter fullscreen mode Exit fullscreen mode
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
Enter fullscreen mode Exit fullscreen mode
Output:
8c42f1d (Alex 2026-06-01) const apiUrl = ...
Enter fullscreen mode Exit fullscreen mode
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
Enter fullscreen mode Exit fullscreen mode
You’ll get something like:
* 8ad32 Fix login bug
|
| * 7bd21 Add dashboard
|/
* 91cd1 Initial commit
Enter fullscreen mode Exit fullscreen mode
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
Enter fullscreen mode Exit fullscreen mode
Unstage files:
git restore --staged index.js
Enter fullscreen mode Exit fullscreen mode
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
Enter fullscreen mode Exit fullscreen mode
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 Purposegit 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! π
λ΅κΈ λ¨κΈ°κΈ°