Lesson 14 / 28
What Rebase Does
Replay your commits on a new base with git rebase, and know why you never rebase shared branches.
Rebase onto main
This replays your branch's commits on top of the latest main, one by one, instead of creating a merge commit.
git switch feature/login
git rebase main
Output:
Successfully rebased and updated refs/heads/feature/login.
Rebase vs merge
Merge preserves history exactly as it happened, with branches visible. Rebase rewrites commit history into a straight, linear line — cleaner to read, but the commits get new hashes.
Never rebase shared history
Since rebase rewrites commits, never rebase a branch that others have already pulled — it forces everyone to fix their history. Rebase only your own unpushed local work.