Proper way of merging a feature branch into another feature branch

54 Views Asked by At

Recently I faced the following issue:

Say I have three branches - master, branch_feature1, branch_feature2. Lets assume that the two features are being developed by different people (developer 1 and developer 2). Developer 2 realizes that he will be needing parts of feature 1 for feature 2. So, he pulls branch_feature1 into branch_feature2.

Now, he makes some changes in feature2 which change some files of feature 1 (lets refer to these changes as common_changes). Now, branch_feature2 gets merged into master. Now when developer 1 takes a pull from master (to rebase his work to the latest master), some files have changed in his work (git won't give a conflict since developer 2 made those 'common_changes' on top of branch_feature1 commits). This is a major issue since developer 1 doesn't know about 'common_changes' which were made on top of his commits by some other developer.

Edit: Here's a very simplified example of my issue:

Say branch_feature1 has two commits on top of master:

commit 1 which changes the file feature1_constants.h:

int feature1_constant = 10;

commit 2 which changes the file common_constants.h:

int common_constant = 100;   // say that in master branch this value was 10 and was changed to 100 in commit 2

Now developer 2 pulls branch_feature1 into his branch; so that commit 1 and commit 2 will be a part of branch_feature2 as well. Developer 2 makes a commit (say commit 3) which changes common_constants.h and adds some more files for his own feature (feature 2):

int common_constant = 10; // changed from 100 (from commit 2) to 10

Now, commit 3 is on top of commit 2. So when branch_feature2 gets merged into master and then gets pulled by developer 1, git won't report a conflict for common_constants.h since commit 3 is on top of commit 2.

So, whats the correct way of incorporating parts of feature 1 into feature 2? If I simply do a git merge, there is a chance that some files of feature 1 can be changed by some other developer on the top of my commit.

Thanks in advance!

0

There are 0 best solutions below