Say you started feature-b from feature-a instead of from main. Now feature-a isn’t going anywhere, and a normal rebase would drag its commits along. --onto takes only mine.
git rebase --onto main feature-a feature-b
Read it as: take the commits on feature-b that aren’t on feature-a, and replay them on top of main. The last argument is the branch to move; if you’re already on it, you can leave it out. Afterwards, git log --oneline main..feature-b shows only your own commits.
It’s also useful for cutting commits out. To drop HEAD~4 and HEAD~3 and keep the commits after them:
git rebase --onto HEAD~5 HEAD~3
That replays everything after HEAD~3 onto HEAD~5, so the two commits in between are gone from the branch.
The three positions are easy to mix up, which is why I’d write them out in full instead of relying on HEAD. If it goes wrong, git reset --hard ORIG_HEAD right after the rebase puts the branch back, though that throws away uncommitted work too, so start with a clean tree.
Like any rebase, this gives the commits new hashes. If feature-b was already pushed and others use it, they’ll have to deal with rewritten history, and you’ll need a force push.
Further reading: git-rebase documentation