Rebase rewrites commit history. It lets you take commits from one branch and apply them on top of another. Instead of a messy sequence of merges, you get a linear, readable history. This matters when your codebase grows, and you need to trace the evolution of every change without wading through noise.
What Git Rebase Does
When you run git rebase, Git finds the common ancestor of your current branch and the target branch. It then temporarily removes your commits, applies the target branch updates, and reapplies your commits on top. The result: the branch now looks like it began from the latest state of the target branch.
Why Rebase Is Powerful
- Clean history: Merge commits can clutter logs. Rebase keeps the commit flow smooth.
- Easier debugging: A linear history makes
git bisectfaster and more accurate. - Better collaboration: Rebasing before pushing reduces conflicts for others.
Risks of Rebasing
Rebase changes commit IDs. That can break shared branches if used recklessly. Never rebase commits that others have already based work on. Keep rebasing local until you’re certain no one else depends on the original history.