ADVERTISEMENT
Google AdSense Slot (headerLeaderboard)

Set your Publisher ID in src/config/ads.ts to display live ads.

Git Version Control Tutorial• 7 min read

Git Rebase vs Merge & Linear History

Replaying commits with git rebase, interactive rebasing, squashing, and the Golden Rule

Rebasing replays your feature commits on top of another base tip, creating a clean, completely linear commit history without extraneous merge commits.

The Mechanics of Rebase vs Merge

Merging preserves historical chronological order and creates a 3-way merge commit.

Rebasing rewrites commit history by lifting your feature commits and replanting them one-by-one at the tip of main.

Interactive Rebase (git rebase -i HEAD~3): Allows editing, reordering, dropping, or squashing ("squash" or "fixup") messy micro-commits into a single clean commit.

THE GOLDEN RULE OF REBASING: Never rebase commits that have been pushed to a public shared branch! Rebasing rewrites commit SHA hashes and breaks team member repositories.

Interactive Rebase Command Menu
# Squashing 3 commits into 1 before submitting a Pull Request:
# git rebase -i HEAD~3

# In the interactive editor:
pick e3b4c12 feat: add login modal
squash 8f9a234 fix: typo in modal title
squash 4d1e902 fix: add missing button styling

# Result: All 3 commits are condensed into 1 clean commit!
Squashing keeps public commit history clean and readable.
Warning / Pitfall

Never rebase public shared branches (like main). Only rebase private local feature branches before opening a pull request.

ADVERTISEMENT
Google AdSense Slot (inContentBanner)

Set your Publisher ID in src/config/ads.ts to display live ads.

Test Yourself With Exercise

+15 XP

What is the "Golden Rule of Git Rebasing"?