Photo of Gil Creque in a pink TV

Worm Icon R e b a s e O n l y T h e L a s t F e w C o m m i t s O n t o A B r a n c h

🌱 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