Rebasing, and how it's different from merge
Rebase is the Git feature that confuses people most — not because it's conceptually hard, but because tutorials often explain the command before the reason to use it. Here's the reason first.
What merge does vs. what rebase does
Merge takes two branches' histories and joins them with a new merge commit that has two parents. The history that results is true — it shows exactly when each branch diverged and rejoined — but it can get messy-looking on a branch that's been merged from main repeatedly.
Rebase takes your branch's commits and replays them one by one on top of another branch's current tip, as if you'd started your work from there in the first place:
git switch feature-x
git rebase main
The result is a straight, linear line of commits — no merge commit, no branching-and-rejoining shape in the history. It looks like your work happened cleanly after everything currently on main, even though it didn't, chronologically.
Why that's sometimes worth it
A linear history is easier to read and easier to bisect (Git has a bisect command for binary-searching history to find which commit introduced a bug — it works much better on a straight line than a tangle of merge commits). Rebasing your own feature branch onto the latest main before opening a pull request is a common, low-risk use: you get a clean, easy-to-review commit sequence.
The one rule: never rebase shared history
Rebase rewrites commits — the replayed commits are new objects with new hashes, even though the content looks the same. If you rebase a branch other people have already pulled and built on top of, their history and yours no longer agree, and everyone downstream has a bad time reconciling it. The rule of thumb: rebase freely on branches only you are using; use merge (or coordinate explicitly) once a branch is shared.
The checkpoint for this lesson
On your practice repository: branch from main, make a commit on main itself (simulating a teammate's work), switch back to your feature branch, and run git rebase main. Compare git log --oneline --graph --all before and after — that's the shape difference this lesson is about, made concrete.