What does git rebase --onto do?
git rebase --onto newbase oldbase branch moves only the commits after oldbase onto a different base. It lets you transplant part of a branch, for example when a branch was started from the wrong parent.
Explain it simply
Imagine you built a feature on top of someone's half-finished branch, and that branch has since been merged in a different shape. You want to lift your commits off the old parent and set them on main.
The three arguments read: put onto this new base the commits that come after this old base, belonging to this branch. If feature-b was started from feature-a, then git rebase --onto main feature-a feature-b takes only feature-b's own commits, those after feature-a, and replays them on main. A plain git rebase main would drag feature-a's commits along too.
Example
Before: main --- M
\
A1--A2 (feature-a)
\
B1--B2 (feature-b)
git rebase --onto main feature-a feature-b
After: main --- M --- B1'--B2'What to say in the interview
"rebase --onto takes a new base, an old base and a branch, and replays only the commits between the old base and the branch tip onto the new base. I use it to move a stacked branch off its original parent without carrying the parent's commits along."