Important Bits

git rebase --onto for feature branches

September 26, 2020

I run into this every couple of weeks:

  1. branch off of dev to make feature-1
  2. put feature-1 up for code review, and start working on feature-2 by branching from feature-1
  3. feature-1 is eventually merged into dev, so feature-2’s commits need to change to be on top of dev as well
git rebase --onto dev feature-1 feature-2

assuming you already have branch feature-2 checked out (because you are actively working on it), you can remove the last argument (the target branch to change)

git rebase --onto dev feature-1

so it reads like:

git rebase --onto <to> <from> <branch-to-manipulate>

more details at

I like this quote:

The current branch is reset to <upstream>, or <newbase> if the —onto option was supplied. This has the exact same effect as git reset —hard <upstream> (or <newbase>). ORIG_HEAD is set to point at the tip of the branch before the reset.

Adam Sullovey

Written by Adam Sullovey, powered by Gatsby.
Find me on codepen, github, or at Toronto meetups.

tags: git