🧹 Rebase = Clean History
Merge commits are messy. Rebase creates clean history. Linear, readable, professional.
❌ Merge (Messy)
* Merge commit |\ | * Feature commit | * Feature commit | * Feature commit * | Main commit * | Main commit
✅ Rebase (Clean)
* Feature commit * Feature commit * Feature commit * Main commit * Main commit
📝 Rebase Commands
# Basic rebase git checkout feature-branch git rebase main # Interactive rebase (squash commits) git rebase -i HEAD~5 # Rebase with options git rebase --abort # Cancel rebase git rebase --continue # Continue after conflict resolution git rebase --skip # Skip current commit # Rebase onto git rebase --onto target-branch source-branch feature-branch # Rebase with merge strategy git rebase -X theirs main # Resolve using theirs git rebase -X ours main # Resolve using ours
🎯 Interactive Rebase
# Interactive rebase - squash commits git rebase -i HEAD~5 # In editor: pick a1b2c3d Fix bug pick e4f5g6h Update tests pick i7j8k9l Add feature pick m0n1o2p Code review changes pick p3q4r5s Final fixes # Change to: pick a1b2c3d Fix bug squash e4f5g6h Update tests squash i7j8k9l Add feature squash m0n1o2p Code review changes squash p3q4r5s Final fixes # Result: One commit with all changes # Rebase options: pick - Use commit reword - Change message edit - Amend commit squash - Combine with previous fixup - Combine, discard message exec - Run command drop - Remove commit
💡 Rebase Best Practices
- Don’t rebase shared branches
- Rebase before merging to main
- Use interactive rebase for cleanup
- Squash related commits
- Write clear commit messages
“Rebase creates clean history. Linear, readable, professional. Essential for Git workflow.”
