Interview Q&A / Git & GitHub

AdvancedQuick answer1 min readUpdated 3 Oct 2026

What does git rebase --onto do?

SHORT ANSWER

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

text
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."

#git#rebase#onto

Related questions

Practise more Git & GitHub questions

Test your recall with short answers, then return to the detailed explanations when you need context.

Open Git & GitHub quick answers →

Get new questions like this by email

One short email when something new and useful lands. No spam, unsubscribe in one tap.

By subscribing you agree to the Privacy Policy.