September 26, 2020
git rebase --onto for feature branches
I need to perform this series of actions every few weeks, but can never remember the commands.
- branch off of
devto makefeature-1 - put
feature-1up for code review, and start working onfeature-2by branching fromfeature-1 feature-1is eventually merged intodev, sofeature-2’s commits need to change to be on top ofdevas 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>
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.