Photo of Gil Creque in a pink TV

Worm Icon RebaseOnlyTheLastFewCommitsOntoABranch

🌱 seed

Suppose you have a branch with a few commits on top of a divergent branch, and you want to rebase only the last few commits onto main. You can use the git rebase command with the --onto option. The following command rebases the last 4 commits onto the main branch:

git rebase --onto main HEAD~4