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:
Git will first rebase the
current-base-branch
on top of thenew-base-branch
. There might be conflicts; which you will have to resolve manually. After that is done, you usually dogit add .
andgit rebase --continue
. It will create a new temporary committemp-commit-hash
for this.After this, Git will now rebase your
current-branch
on top oftemp-commit-hash
. There might be further conflicts and again you will have to resolve them manually. Once done, you continue again withgit add .
andgit rebase --continue
, after which you have successfully rebased yourcurrent-branch
on top thenew-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.