HeadlinesBriefing favicon HeadlinesBriefing.com

Git rebase -i: Demystifying Interactive Rebase

Hacker News •
×

One of the most shocking things I encountered early in my career as a junior dev was the fear surrounding git rebase -i. Even among smarter coworkers, many devs hesitate. Running git rebase -i HEAD~4 opens a text file where each line is an instruction: pick, reword, squash, fixup, drop.

It’s a plan, not an action; nothing has technically happened yet. If you change your mind, simply run git rebase --abort and the branch snaps back to its previous state.\n\nThe safety net is robust. Rebase doesn’t destroy commits; it creates new ones and moves the branch pointer.

Old commits remain in Git’s object database, unreferenced but intact, and the reflog remembers every move. If a mistake slips through, you can restore a prior state with `git reset --hard HEAD@{4}` or `git reset --hard backup-before-rebase`.\n\nConflicts are common, but since you’re dealing with one commit at a time, they’re usually easier than a merge.\n\nIn practice, I let myself rebase my own feature branches freely, pushing with git push --force-with-lease. The takeaway is that any developer worth their salt should comfortably walk through a simple interactive rebase; it’s not just a tool, it’s a confidence builder.