skip to content
Alvin Lucillo

Rebase onto another branch

/ 1 min read

💻 Tech

For example, you’re currently in feature1, which is based on develop branch, when you made local changes and created a new branch feature2 via git checkout -f feature2. Then, you realized that you should have based feature2 on develop. To visualize this, here’s the text representation of the scenario:

develop
    |
    |--- feature1
    |       |
    |       |--- feature2

What you want to happen is:

develop
    |
    |--- feature1
    |
    |--- feature2

So the question is, how do you move all your commits from the top of feature1 to develop? Here’s how you can do it:

git rebase --onto develop feature1 feature2

With feature2 currently checked out, what the command does is find the commits that are in feature2 but not in feature1, then put them on top of develop.