How to rebase a topic branch from one branch to another

fr

Sometimes, we want to rebase a feature or topic branch from one branch to another.

For example, we want to rebase commits H, I, and J from the branch Topic B onto the master branch.

                            H---I---J topicB
                           /
                  E---F---G  topicA
                 /
    A---B---C---D  master

To achieve this, we use rebase --onto <destination> <from> <to>

git rebase --onto master topicA topicB

This will result in the following:

                 H'--I'--J'  topicB
                /
                | E---F---G  topicA
                |/
    A---B---C---D  master

We can find all of this in the Git documentation… but I always forget how to do it.

https://git-scm.com/docs/git-rebase"