Change branch base

Assuming newBase is the branch you want to move your commits onto, oldBase is the old basis for your branch, you can use --onto for that:

git rebase --onto newBase oldBase feature/branch

Given your case:

git checkout PRO # Just to be clear which branch to be on.
git rebase --onto master demo PRO

Basically, you take all the commits from after demo up to and including PRO, and rebase them onto the master commit.


I will try to be as generic as I can be. First, be sure that you are on the desired branch:

git checkout current-branch

Then use the following command (where new-base-branch is the branch which you want to be your new base, and current-base-branch is the branch which is your current base.)

git rebase --onto new-base-branch current-base-branch

If you do not have conflicts, then great - you are done. If you do (in most cases), then please read on.

Conflicts might arise, and you will have to resolve them manually. Git now tries to do a "3-way merge" between your current-branch, current-base-branch and new-base-branch. Roughly this is how git will work internally:

  1. Git will first rebase the current-base-branch on top of the new-base-branch. There might be conflicts; which you will have to resolve manually. After that is done, you usually do git add . and git rebase --continue. It will create a new temporary commit temp-commit-hash for this.

  2. After this, Git will now rebase your current-branch on top of temp-commit-hash. There might be further conflicts and again you will have to resolve them manually. Once done, you continue again with git add . and git rebase --continue, after which you have successfully rebased your current-branch on top the new-base-branch.


Note: If you start to mess up, then you can do git rebase --abort anytime during the rebase process and get back to the starting point.

Tags:

Git