- Null Pointer Club
- Posts
- Git Magic: 7 Advanced Git Commands You’ll Wish You Knew Sooner
Git Magic: 7 Advanced Git Commands You’ll Wish You Knew Sooner
Because you’re better than git push --force and hoping for the best.
We all know the basics: git clone
, git commit
, git push
, maybe even a git stash
when things go sideways.
But Git is more than a version control system—it's a time machine, a safety net, a secret weapon. The catch? Most devs never explore past the surface.
Today’s issue is for those ready to level up.
Choose the Right AI Tools
With thousands of AI tools available, how do you know which ones are worth your money? Subscribe to Mindstream and get our expert guide comparing 40+ popular AI tools. Discover which free options rival paid versions and when upgrading is essential. Stop overspending on tools you don't need and find the perfect AI stack for your workflow.
Here are 7 advanced Git commands that feel like magic—because once you know them, you’ll wonder how you ever coded without them.
1. git reflog
Undo anything. Yes, anything.
Deleted a branch by mistake? Did a bad rebase? Lost a commit?
Run this:
git reflog
It shows a log of every change made to HEAD—allowing you to recover commits even if you thought they were lost forever.
git checkout HEAD@{2}
Why you’ll love it:
Your safety net when Git feels like it’s working against you.
2. git cherry-pick
Pull specific commits from anywhere.
Let’s say someone fixed a bug in a different branch, and you want just that one commit—without merging the whole branch.
git cherry-pick <commit-hash>
Why you’ll love it:
Precision control without unnecessary merges.
3. git bisect
Find the exact commit that broke your code.
You have a bug but no clue when it was introduced. Rather than manually checking commits, let Git binary search it:
git bisect start
git bisect bad # current version with bug
git bisect good <commit-hash> # older version without bug
Git will walk you through testing each midpoint. Once you’re done:
git bisect reset
Why you’ll love it:
Find bugs faster. Blame less. Debug smarter.
4. git grep
Search your repo like a pro.
Forget grep
or opening every file manually. Git has a built-in search:
git grep 'functionName'
Even better:
git grep 'TODO' HEAD
Why you’ll love it:
Search your codebase at lightning speed, right from the terminal.
5. git worktree
Work on multiple branches without context switching.
Ever stash your work to check something on another branch? Git Worktrees let you avoid that entirely.
git worktree add ../feature-temp feature-branch
This creates a new directory where you can work on another branch side-by-side.
Why you’ll love it:
Multitask cleanly. No more stashing wars.
6. git clean -fd
Nuke all untracked files and directories.
Sometimes your working directory is just… a mess. Temporary files. Build outputs. Stuff you didn’t add to .gitignore
.
Run this:
git clean -fd
Warning: This deletes untracked files. Use -n
to preview:
git clean -fdn
Why you’ll love it:
Like a spring cleaning for your repo. Fast and final.
7. git commit --fixup
+ git rebase -i --autosquash
Make your commit history look like you planned it that way.
Let’s say you pushed a commit, then later fixed a typo. Instead of a sad little “fix typo” message polluting your log, use:
git commit --fixup <commit-hash>
Then clean it up:
git rebase -i --autosquash HEAD~3
Why you’ll love it:
Keep your history clean, even when your dev process wasn’t.
Nullpointer Dev Drills
Try these out in a dummy repo this week:
Break something, then recover it with
git reflog
.Test
git bisect
on a controlled bug.Set up a parallel
git worktree
and switch without losing progress.
Final Thought
Git isn’t just about collaboration. It’s about confidence.
These commands don’t just save time—they save stress, confusion, and those “what did I just do?” moments.
So the next time Git starts acting up…
Don’t panic.
Don’t delete your repo and clone it again.
Just reflog, bisect, grep, fixup—and breathe.
Happy committing,
— Team Nullpointer
Reply