Working with Git day-to-day can feel like second nature—until you hit one of those moments where you wish you knew the right command.
After years of tripping over the same pain points, here’s a practical list of Git commands that act like superpowers.
1. git reflog – The Time Machine
Accidentally deleted a branch? Reset to the wrong commit? Reflog is your safety net.
git reflog
# Find your lost commit hash
git checkout -b recovery-branch <hash>
git bisect– The Bug Hunter
You know something broke, but not when? Let Git binary search it for you.
git bisect start
git bisect bad HEAD
git bisect good <known-good-commit>
# Git guides you to the offending commit
git stash --include-untracked– The Context Switcher
Need to switch branches but don’t want to commit messy work?
git stash push -u -m "work in progress on feature X"
# Do work on another branch
git stash pop
git cherry-pick– The Surgical Strike
Grab just the commit(s) you want from another branch.
git cherry-pick <commit-hash>
# Or for a range:
git cherry-pick <start-hash>^..<end-hash>
git worktree– The Parallel Universe
Work on multiple branches at once in separate directories.
git worktree add ../feature-branch feature-branch
# Now you have two working directories for the same repo
git clean– The Janitor
Clear out untracked files and directories. Perfect for cleaning up after switching branches.
git clean -fd
git shortlog– The Historian
Summarize commits by author or message. Useful for release notes or contributor stats.
git shortlog -sn
git blame– The Detective
Find out who last touched a specific line of code.
git blame <file>
git log --graph– The Storyteller
Get a clean, visual commit history.
git log --graph --oneline --decorate --all
git reset– The Undo Button
Rollback commits safely, either keeping or discarding changes.
# Keep changes staged
git reset --soft <commit>
# Discard changes completely
git reset --hard <commit>
Honorable Mentions: Modern Alternatives
git switch -c new-branch→ friendlier thangit checkout -b- Why? Because
git switchis dedicated just to switching/creating branches, whilegit checkoutis overloaded (it can also reset files, detach HEAD, etc.). This makesswitchsafer, clearer, and easier to learn. I’m still working on getting this to replace my alias usage ofgit co -b
- Why? Because
git restore <file>→ safer way to discard changes- Why? Because
git restoreonly affects working directory changes, whilegit checkoutcould also switch branches or detachHEAD. This narrower scope makes it less error-prone for beginners.
- Why? Because
Wrapping Up
These aren’t obscure tricks — they’re practical tools that save time, frustration, and sometimes entire projects (seriously, git reflog).
Mastering them means fewer “oh no” moments and faster context switching.
Up next on “need to learn/master” - git worktree - which sounds pretty interesting.