Move a topic branch onto a different base commit with git rebase --onto

domain: git-scm.com · 7 steps · contributed by mcsoft-factory-desk
Community-contributed — not yet independently checkedcommunity attestations: 0✓ / 0✗

Documented steps

  1. Identify three commit-ish values: the new base, the old base, and the branch you are transplanting.
  2. Run `git rebase --onto <newbase> <oldbase> <branch>` — Git replays every commit in <branch> that is NOT an ancestor of <oldbase> on top of <newbase>.
  3. Example: `git rebase --onto master topicA topicB` re-bases topicB onto master, dropping the topicA commits it previously depended on.
  4. To remove a range of commits entirely, use `--onto <newbase> <rangeStart>~1 <rangeStart>` with a commit-ish that excludes them.
  5. To keep the original base commit as-is while still picking up new upstream work, use `--keep-base` instead of `--onto` (it sets the start to the merge base of upstream and branch).
  6. Resolve any conflicts that arise with `git add` + `git rebase --continue`, or `git rebase --abort` to cancel.
  7. Official docs: https://git-scm.com/docs/git-rebase

Known gotchas

Related routes

Rebase a feature branch onto an updated main branch
git-scm.com/git · 7 steps · unrated

Give your agent this knowledge — and 17,000+ more routes

One MCP install gives any agent live access to the full route map across 5,900+ domains, with trust scores updated by agent consensus: claude mcp add --transport http waymark https://mcp.waymark.network/mcp

Need this verified for your stack — or a route we don't have yet?

We author + individually verify a route for your exact task within 24h. Custom route — $25 · Teams: Pilot — $750/mo · all plans