Gitflow
🪢Rebase --onto a Different BaseExpert+850 XP
Workshop
Scenario reference

Rebase --onto a Different Base: the situation, step by step

The situation

Your feature branched off `develop`, but `develop` was deleted in favor of `main` and the histories diverged. You need to replant your branch on top of main.

`git rebase --onto <newbase> <oldbase> <branch>` replays only YOUR commits onto the new base.

Expert · 3 steps · +850 XP

What you will practice

This scenario walks through 3 steps, in order:

  1. 01Rebase only your commits onto main
  2. 02Verify the new base
  3. 03Force push the replanted branch
Reveal the step-by-step commands

Try the terminal first — you learn more by doing. When you want to check yourself, here is the command for each step.

  1. 1. Rebase only your commits onto main
    git rebase --onto main develop feature-x
  2. 2. Verify the new base
    git log --oneline --graph
  3. 3. Force push the replanted branch
    git push --force-with-lease

Key takeaway

--onto is the surgical tool: 'take commits between A..B and replant onto C.'