If you’re like me, you probably use Git every day with commands like git add
, git commit
, and git push
. But Git has superpowers-commands that can save hours, rescue broken codebases, and help you understand who wrote what and why.
In this post, I’ll break down four powerful (but often underused) Git commands:
git bisect
git stash -p
git blame
git cherry-pick
For each command, I’ll share:
✅ What problem it solves
📖 The story behind why you’d use it
🛠️ How to use it with real examples
Let’s dive in!
🕵️♂️ 1. git bisect
- Hunt Down the Bug Like a Detective
✅ What Problem It Solves:
You’re working in a large codebase. Something used to work, and now it’s broken. You don’t know which commit caused the bug.
📖 The Story:
Let’s say you run a test that used to pass:
npm run test
Now it’s failing. But you have hundreds of commits. Manually checking them one-by-one is a nightmare. That’s where git bisect
becomes your bug detective!
🛠️ How to Use It:
git bisect start
git bisect bad # current commit is bad
git bisect good v1.0.0 # last known good commit
Git now checks out a commit in the middle. You test it. If it’s good:
git bisect good
If it’s bad:
git bisect bad
Git will narrow it down-binary search style-until it tells you the exact commit that introduced the bug.
To finish:
git bisect reset
🚀 Great for: bug hunters, testers, QA engineers, or developers fixing regressions.
🧺 2. git stash -p
- Stash Only What You Want
✅ What Problem It Solves:
You’re working on multiple changes but only want to temporarily save part of it -not everything.
📖 The Story:
You’re fixing a bug and suddenly get a Slack message:
"Hey, can you quickly switch branches and check this issue?"
You’ve edited 10 files but only want to stash 2.
🛠️ How to Use It:
git stash -p
Git will go file-by-file, hunk-by-hunk, asking:
Stage this hunk [y,n,q,a,d,/,e,?]?
Press:
-
y
to stash this hunk -
n
to skip -
q
to quit
Now your working directory is clean, and you can safely switch branches.
🧠 Pro tip: Later, use
git stash pop
to bring it back.🚀 Great for: multitaskers, bug-fixers, or anyone working with large diffs.
👤 3. git blame
- Find Out Who Wrote What (And Why)
✅ What Problem It Solves:
You’re staring at a confusing line of code and wondering:
Who wrote this? When? And maybe… why?
📖 The Story:
You find this suspicious line:
if (isActive && data.length > 0) {
You’re not sure if it’s safe to remove. Time to investigate.
🛠️ How to Use It:
git blame src/utils/isActive.js
It will show:
a1b2c3d4 (Alice 2023-11-12) if (isActive && data.length > 0) {
Now you know who, when, and which commit it came from. Want to dig deeper?
git show a1b2c3d4
🚀 Great for: understanding legacy code, reviewing changes, or contacting the original author for context.
🍒 4. git cherry-pick
- Pick Just One Commit and Apply It Elsewhere
✅ What Problem It Solves:
You want to move just one commit from one branch to another-without merging everything.
📖 The Story:
You fixed a bug on feature/login
. Your teammate says:
"That fix is perfect! Can you apply it to
main
too?"
Instead of re-writing the code or merging the whole branch, you can cherry-pick that one commit.
🛠️ How to Use It:
- Find the commit hash:
git log --oneline
Example output:
b7f4d1f Fixed the login redirect bug
- Switch to
main
:
git checkout main
- Cherry-pick the commit:
git cherry-pick b7f4d1f
Boom. That single fix is now on main
.
🚀 Great for: hotfixes, backporting features, or syncing branches surgically.
🧠 Summary: When to Use What
Command | Use Case | Best For |
---|---|---|
git bisect |
Find which commit broke something | Bug fixers, testers |
git stash -p |
Temporarily save only part of your changes | Multitaskers, hotfix responders |
git blame |
See who wrote a specific line and why | Legacy explorers, reviewers |
git cherry-pick |
Move a specific commit to another branch | Feature syncing, hotfixing |
Top comments (0)