DEV Community

Ayush Poddar
Ayush Poddar

Posted on Originally published at poddarayush.com

Advanced Git Rebasing: The Powerful --onto Flag

๐Ÿ“ This post is part of my โ€œShortsโ€ series, where each post is concise and hyper-focused on a single concept.

Apart from the interactive mode of git-rebase, you can also use the --onto flag to change the current base of your feature branch.

Command

git rebase --onto <newBase> <oldBase> <featureBranch>
Enter fullscreen mode Exit fullscreen mode

What does it do?

Consider the scenario below:

Current feature branch scenario

Letโ€™s say that you donโ€™t want featureB branch to be based off featureA, but you want it to be branched off the main branch, as shown below:

Desired scenario

The --onto flag will help you to change the base of featureB branch from featureA to main. The command that you need to use will be:

git rebase --onto main featureA featureB
Enter fullscreen mode Exit fullscreen mode

Sources

Top comments (0)