Working with Git is a daily routine for developers—but it’s also where a lot of frustration begins. Ever lost progress due to a bad reset? Struggled to find the commit that broke everything? Or needed to switch branches but didn’t want to lose your work? These aren’t just inconveniences—they’re time killers. In this guide, you’ll discover 7 practical Git commands that will help you debug smarter, switch faster, and manage your repository without stress.
We recently wrote about Git in more detail — you can read it here - 15 Git Commands That Cover 90% of a Developer’s Daily Workflow.
1. git bisect – Find the Breaking Commit with Binary Search
Let’s say your app started failing somewhere between versions v1.2.0 and v2.0.0. You could guess randomly… or use git bisect to track the exact commit that broke it.
git bisect start
git bisect bad v2.0.0
git bisect good v1.2.0Git will check out the midpoint commit. You test it:
- If the bug is present:
git bisect bad - If the bug is gone:
git bisect good
Repeat this a few times until Git pinpoints the exact faulty commit and the author.
2. git switch – Quick and Safe Branch Navigation
Instead of the all-in-one (and confusing) git checkout, use git switch to focus solely on moving between branches:
git switch feature/signup-form # move to existing branch
git switch - # return to previous branch
git switch -c bugfix/404-page # create & switch to new branchIt’s faster and safer, especially when multitasking across branches.
3. git restore – Revert Changes File-by-File
Need to undo local changes but only for specific files? git restore is your friend:
git restore src/App.tsx # restore one file
git restore --staged *.css # unstage .css files
git restore --source=HEAD~1 --worktree . # revert all files to previous commitUnlike reset, this is a surgical tool that avoids unnecessary data loss.
4. git rebase -i – Clean Up Commit History
Need to squash, reorder, or reword commits before pushing? Try:
git rebase -i HEAD~3Then you’ll see something like:
pick a1b2c3d Fix login bug
pick b2c3d4e Add error logger
pick c3d4e5f Remove debug printReorder or combine them with:
pick c3d4e5f Remove debug print
squash b2c3d4e Add error logger
reword a1b2c3d Fix login bugYou now have a tidy commit history ready to share.
5. git stash – Hide Unfinished Work Temporarily
Need to pause what you’re doing and switch tasks without committing half-done work?
git stash save "WIP: login refactor"
git stash list
git stash apply stash@0 # apply without removing
git stash pop # apply and removeYou can stash multiple times and retrieve only the changes you need.
6. git cherry-pick – Bring Over Specific Commits
Want to copy a fix from another branch without merging everything?
git cherry-pick abc1234 # single commit
git cherry-pick 111aaa..444ddd # commit range (excludes first)
git cherry-pick --continue # resume after conflict resolutionThis is useful when you want just one hotfix, not the whole feature branch.
7. git log --graph – Visualize Your Project History
Understand how your branches diverged or merged with:
git log --graph --decorate --oneline --all-
--graphdraws tree structure -
--decorateshows branch/tags -
--onelinesimplifies view -
--allincludes all branches
Make it easier by aliasing it:
git config --global alias.graph "log --graph --decorate --oneline --all"
git graphGreat for understanding what really happened in your project timeline.
🧠 Final Thought
Git isn’t just about commit and push. The right command at the right time can prevent bugs, save hours, and keep your repo clean.
Which command saved you the most time? Share your Git gems—we might feature them next.