Rebase Onto: Moving a Branch to a New Base

A real branch, accidentally built on a stale one. Transplant it directly onto the real correct base.

A real, honest mistake: feature/party-snacks was branched from old/spice-experiments — a genuine, abandoned experiment nobody meant to build on top of — instead of master. Every real commit on party-snacks now carries that stale experiment along with it.\n\ngit rebase --onto is the real, three-argument form of rebase built exactly for this: "replay these commits, starting from where they actually diverged from the old base, directly onto this new one." One real command, and the stale base is gone entirely — not just hidden, genuinely removed from the branch's ancestry.

Discovering the Real Wrong Base

git log --oneline feature/party-snacks -4

A real, stale "Add spice experiments notes" commit sits right there in the ancestry — the tell-tale sign of branching from the wrong place.

The Real Three-Argument Rebase

git rebase --onto master old/spice-experiments feature/party-snacks

Read as: take everything on feature/party-snacks since it diverged from old/spice-experiments, and replay it directly onto master instead.

Confirming the Real Transplant

git log --oneline feature/party-snacks -4

The stale commit is genuinely gone — not hidden, not merged around, actually removed from this branch's real ancestry. Only the branch's own two real commits remain, now sitting directly on master.

git rebase --onto <newbase> <oldbase> <branch>

The real, three-argument form of rebase: replays only the commits on <branch> that came after it diverged from <oldbase>, directly onto <newbase>. Confirmed directly in this lab: the stale old/spice-experiments commit was completely excluded from the result.

🔍 Discover the Real Wrong Base

A stale, real commit sits right in this branch's ancestry.

cd ~/team-recipes && git log --oneline feature/party-snacks -4

student@lab:~$ cd ~/team-recipes && git log --oneline feature/party-snacks -4 863ef0d (HEAD -> feature/party-snacks) Add veggie platter to party snacks c594017 Add party snacks recipe b69df87 (old/spice-experiments) Add spice experiments notes f10a08e (origin/master, origin/HEAD, master) Merge pull request: rebasing policy

🌳 Transplant It With the Real Three-Argument Rebase

One real command: replay only party-snacks' own commits, directly onto master.

cd ~/team-recipes && git rebase --onto master old/spice-experiments feature/party-snacks

student@lab:~$ cd ~/team-recipes && git rebase --onto master old/spice-experiments feature/party-snacks Successfully rebased and updated refs/heads/feature/party-snacks.

✅ Confirm the Stale Base Is Genuinely Gone

Not hidden — actually removed from this branch's real ancestry.

cd ~/team-recipes && git log --oneline feature/party-snacks -4

student@lab:~$ cd ~/team-recipes && git log --oneline feature/party-snacks -4 9a89b2b (HEAD -> feature/party-snacks) Add veggie platter to party snacks 3b85461 Add party snacks recipe f10a08e (origin/master, origin/HEAD, master) Merge pull request: rebasing policy 923abaf Document the team's rebasing policy

Lab 3.1.5 complete — Block 3.1 complete. A real branch, transplanted from the wrong base to the right one:\n\n\n Wrong base discovered : ✅ stale commit found\n Transplanted : ✅ rebase --onto\n Stale commit confirmed gone : ✅ verified\n

Enable JavaScript to run the live terminal and track your progress.