0

I have different feature branches and one main branch:-

main
feature1
feature2
feature3

feature2 and feature3 branches are behind master by a few commits. Before that feature1 branch is ahead of the main branch.

Firstly feature3 needs to merged and then feature2.

I want to merge all the feature branches in a way that i dont lose the contents and moreover the new contents needs to be added. In the end the data of all the feature branch should be in the main branch.

I am confused like should I first merge the feature1 branch as its ahead of the main branch or first I merge feature3 first and feature2 into the feature1 branch and create a pull request from the feature1 branch. Also which are the commands that i can use in order to accomplish this?

The files in all feature 1, 2, 3 is modified and because of that i am facing merge conflict error.

What i did:- Firstly i created a dummy branch from the main branch. Merged the changes of feature3 branch in to the dummy branch. Now when i am trying to merge the feature2 branch into dummy branch doing so i am getting merge conflict error.

can someone guide me here?

PforPython
  • 58
  • 7
  • 1
    If they are _really_ independent from each other, you can merge them in any order _from git's POV, at least_, git does not care. You might have other considerations in mind, that are not strictly VCS-related.... like _I will merge feature1 first because then I can pull those changes into feature2 so that I can then test a part of feature2 that is related... but not dependent_. – eftshift0 Oct 20 '22 at 09:52
  • Besides what @eftshift0 said, you could combine these with an "octopus merge", which acts as a sort of proof that none of the three branches has any conflict with any of the others. But octopus merges are a bit tricky and don't do anything that regular merges don't do (in fact, the "sort of proof" above is because regular merges can do MORE than octopus merges can). – torek Oct 20 '22 at 09:56
  • Does this answer your question? [Merging multiple branches with git](https://stackoverflow.com/questions/5292184/merging-multiple-branches-with-git) – Michael Delgado Oct 20 '22 at 14:37
  • To test I created a example branch and merged feature3 first and then when i created pull request for feature 2 to merge into example branch I got this error Conflict: This file was modified on source and destination. – PforPython Nov 02 '22 at 14:31
  • Is this helpful? https://www.atlassian.com/git/tutorials/using-branches/merge-conflicts, https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/addressing-merge-conflicts/resolving-a-merge-conflict-using-the-command-line, https://support.atlassian.com/bitbucket-cloud/docs/resolve-merge-conflicts/ – LinFelix Nov 03 '22 at 12:35

1 Answers1

0

You could bring feature2 and feature3 in sync with master again by rebasing them on master. Just be sure you pulled your master to the latest changes. Then checkout feature3 and run git rebase master, now you could merge it into master, do the same with feature2 and you are done.

Note: it does not really matter here if you merge feature1 first or after. Just be sure to also rebase it, if you merge it after merging the other two branches.

jugendhacker
  • 126
  • 7
  • To test I created a example branch and merged feature3 first and then when i created pull request for feature 2 to merge into example branch I got this error Conflict: This file was modified on source and destination @jugendhacker – PforPython Nov 03 '22 at 12:19