Read more at https://git-scm.com/book/en/v2/Git-Branching-Rebasing

The basic premise is that I had a feature branch Feature1 and I branched off Feature2 branch from it. This is very common in the case that Feature 2 actually needs things from Feature 1, and you can’t wait for Feature1 branch to get merged in the main branch.

Now, after Feature1 is merged into main branch, this is how we can rebase Feature2 branch so it branches off from main instead of from Feature1.

git rebase --onto main Feature1 Feature2

This says: Go to Feature2 branch, figure out the patches since it diverged from Feature1, and replay these in Feature2 as if it was branched off from main.

Another way to see git rebase --onto A B C is that it takes commits B..C, branches off C from A and then applies the commits on top of it.