Git Rebase vs Merge
Also Known As
git rebase
git merge
linear history git
rebase vs merge
TL;DR
Merge preserves branch history with a merge commit — rebase rewrites commits onto the target branch for a linear history.
Explanation
git merge creates a merge commit that joins two branch histories — history is preserved exactly. git rebase replays feature branch commits on top of the target, rewriting SHAs — produces a clean linear history but changes commit identity. Interactive rebase (git rebase -i) allows squashing, reordering, and editing commits. Golden rule: never rebase commits that have been pushed to a shared branch — others' history diverges. Rebase is preferred for local cleanup; merge is safer for shared branches.
Common Misconception
✗ Rebase is always cleaner than merge. Rebase rewrites history — on shared branches this forces every collaborator to reset their local copy, breaking their work.
Why It Matters
Rebasing shared commits forces teammates to reconcile diverged history — a common source of team confusion and accidental data loss. Understanding when each is appropriate prevents painful conflicts.
Common Mistakes
- Rebasing a branch others are working on — forces force-push and history divergence.
- Using git pull --rebase without understanding that it replays local commits on the remote — can cause conflicts.
- Squashing too aggressively — losing useful incremental commits that explain why a change was made.
Avoid When
- Never rebase commits that have already been pushed to a shared branch — it rewrites history others depend on.
- Avoid force-pushing to main or develop — it overwrites work and breaks others' local copies.
When To Use
- Use rebase to clean up local feature branch commits before opening a pull request.
- Use merge to integrate a completed feature into a shared branch — preserves context.
Code Examples
✗ Vulnerable
# Rebasing a shared branch others are using
git checkout main
git rebase origin/develop # rewrites main — force-push required
git push --force origin main # breaks everyone else's local main
✓ Fixed
# Local feature branch cleanup before PR
git checkout feature/my-feature
git rebase -i main # squash WIP commits, clean up messages
git push origin feature/my-feature # first push — safe to rebase
# Merging into main (preserves feature branch context)
git checkout main
git merge --no-ff feature/my-feature # explicit merge commit
Tags
🤝 Adopt this term
£79/year · your link shown here
Added
31 Mar 2026
Views
31
🤖 AI Guestbook educational data only
|
|
Last 30 days
Agents 1
No pings yesterday
Amazonbot 12
Perplexity 8
Google 4
SEMrush 3
Ahrefs 2
Majestic 1
Also referenced
How they use it
crawler 27
crawler_json 3
Related categories
⚡
DEV INTEL
Tools & Severity
⚙ Fix effort: Medium
⚡ Quick Fix
Use merge for shared/public branches, rebase for cleaning up local feature branches before opening a pull request
📦 Applies To
cli
🔍 Detection Hints
git push --force on shared branches
Auto-detectable:
✗ No
⚠ Related Problems
🤖 AI Agent
Confidence: Low
False Positives: High
✗ Manual fix
Fix: High
Context: File