Discovering Master Has Moved
git switch feature/dessert-menu
git fetch origin
git log --oneline master..origin/master
Two real commits, genuinely landed on master while you were working elsewhere.
Catching Up With Merge
git merge origin/master --no-edit
git log --oneline --graph -8
A real merge commit, with two parents — both histories fully preserved, exactly as they happened.
Catching Up With Rebase, in a Fresh Clone
git clone ~/recipes-origin.git ~/team-recipes-2
cd ~/team-recipes-2 && git switch --track origin/feature/dessert-menu
git fetch origin
git rebase origin/master
git log --oneline --graph -8
Every real feature commit is replayed on top of the new master — genuinely new hashes, but a completely linear result, as if the feature had been started fresh from today's master.
The Real Trade-off
Merge preserves exactly what happened, including the moment of integration — valuable for traceability, but the graph gets busier. Rebase produces a clean, linear story — easier to read later, but it genuinely rewrites commit hashes, which is only safe on a branch nobody else has already pulled.
While you were setting up feature/dessert-menu, real work continued on master too — two more genuine commits landed there. Your feature branch is now behind, and there are two real, valid ways to catch up: merge master in, or rebase your work on top of it.
This lesson performs both, for real, on the exact same starting point — once with merge in your existing clone, once with rebase in a fresh one — so the real difference in the resulting history is something you see side by side, not just read about.
git rebase origin/<branch>
Replays the current branch's own commits, one at a time, on top of the target branch's current tip — producing a linear history with genuinely NEW commit hashes for every replayed commit. Confirmed directly in this lab: the same three feature commits got entirely different hashes after rebasing (2337c0f vs the original 9d5405c, for example).
Merge vs rebase, the real trade-off
Merge creates one real commit combining two histories, preserving exactly what happened, including a busier graph. Rebase produces a clean, linear graph by replaying commits with new hashes — readable, but only safe before anyone else has based work on the original commits.
Takeaways
- git merge origin/<branch> creates a real merge commit with two parents, preserving both histories exactly as they happened
- git rebase origin/<branch> replays your branch's own commits on top of the target, producing a linear history with genuinely new hashes
- Rebase is only safe on commits nobody else has already pulled or built on — it rewrites history, merge never does
- Most real teams pick different defaults for feature branches (often rebase) versus main itself (almost always merge)