How to rebase last x commits on different branch?

You can use the --onto flag.

git rebase -i HEAD~10 --onto another_branch

Note that this will not create a new branch, nor will it move the actual changes to another_branch.

All changes will be applied to the same branch you are on.

So I suggest do it in several stages:

git checkout -b staging_branch
git rebase -i HEAD~10 --onto another_branch
git checkout another_branch
git merge staging_branch

Leave a Comment