Home > OS >  Merge Master branch into feature-branch which(feature-branch) also has sub branches based on feature
Merge Master branch into feature-branch which(feature-branch) also has sub branches based on feature

Time:09-23

I have a feature-branch which is from master some time back. Now, master branch has advanced and feature-branch has many sub-branches on top of it. I want to have all the new changes from master branch into my feature-branch and that should not disturb any of the existing sub-branches of feature-branch.

If I rebase my feature-branch on master branch, all the sub-branches which were on feature-branch will become stranded (based on my previous experience).

Please let me know how we can handle this.

CodePudding user response:

I merged master branch into my feature-branch and resolved conflicts.

git checkout master
git pull
git checkout feature-branch
git merge master

This didn't disturb any of the comment history in existing sub-branches of my feature-branch.

I did rebase the sub-branches on top of the feature-branch(with latest changes) and all looks fine.

CodePudding user response:

Let's try to answer this with a couple of general illustrations, since we don't know exactly how your particular case look like. First of all, let's agreeing on how merge and rebase differs, before looking at the case your are asking for, where multiple feature branches based on each other.

General case illustrating the difference between rebase and merge

As you are probably aware merge preserves history as it happened, while rebase rewrites it. The difference can be seen in above illustration.

Now, let's try to answer your initial question with a similar illustration; where two feature branches (feature-1 & feature-2) are based on each other, and currently trails behind master.

Particular case with two feature branches based upon each other

Regardless of how you decide to integrate the changes from master into feature-1 (merge or rebase), feature-2 will be left as is (i.e. without the newly integrated changes from master into feature-1). If you then want to integrate all changes into feature-2 you are once again left with the option of merging or rebasing.

If you would decide to rebase feature-2 onto feature-1 (post the initial master integration) Git would then figure out that commits ol42g and 09qr2 are already present, and hence automatically strip those patches out from your rebased version of feature-2.

A cautionary warning: Rebasing branches that have already been published can cause headaches for your team mates, so make sure to keep a tight dialog if that would be the case. To stay on the safe side, don't rebase branches that are already publicly available.

Hopefully it should be clear now what your options are. =)

  • Related