The Golden Rule of Rebase
What you'll learn: The one critical rule that prevents disasters when using Git rebase in collaborative environments.
Why This Rule Exists
You've learned how powerful git rebase is for cleaning up history and creating linear commit timelines. But with that power comes serious responsibility. The golden rule is simple but absolute:
Never rebase commits that have been pushed to a shared repository or exist on branches others are working from.
The Problem Rebase Creates
When you rebase, Git rewrites commit history by creating new commits with different SHA identifiers, even if the changes are identical. Think of it like changing someone's street address without telling them—suddenly their directions don't work anymore.
If your colleagues have based their work on commits you later rebase, their repository becomes incompatible with yours. They'll face confusing conflicts, potential data loss, and significant time wasted reconciling histories that should have been straightforward.
When Rebase is Safe
Rebase freely on:
- Local branches that exist only on your machine
- Feature branches you're working on alone
- Commits that haven't been pushed yet
When to Use Merge Instead
Once commits are shared, use git merge. Yes, it creates less elegant history with merge commits, but it preserves the collaborative timeline everyone relies on.
Think of shared history as published research—once it's out there, you don't go back and change the original paper. You write a correction or follow-up instead.
Key Takeaway: Rebase rewrites history, which is catastrophic for shared work. Keep rebasing local and private; use merge for collaborative branches. This protects your team from untangling impossible conflicts.