Home > Enterprise >  how to correctly merge several feature to main branch
how to correctly merge several feature to main branch

Time:10-12

Here I have a question. I have a main branch and 2 feature branches feature1 and feature2 which is checkout from main, when I finished developing these features, I want them to merge into main.

So I checkout a new branche named merge from main, and see what is going on after mergeing feature1 and feature2 yesterday. And from IDEA, it can be seen these 3 branches like this:

enter image description here

brown line is merge

green line is feature1

blue line is feature2

After testing, today I decided to merge feature1 and feature2 into another main's branch in exactly the same method(checkout a new branch from main and merge feature1 and feature2), but found this strange thing... IDEA showed the branch lines in quite an unapropriate way which like this:

enter image description here

No matter how I change the order of merging feature1 and feature2 it won't help, the branch line graph will always wrong. I don't know why this happening.Is there anything wrong with my merging movement?

I didn't touch my code at all,and no new commits at all, just checkout 2 new branches from main in different days, and doing the same merging process.

CodePudding user response:

I would suggest always rebase before merging, so further merge will be just fast-forward and branch tree will be nice and clean. First, finish work on your feature1, then checkout on it and execute git rebase master, resolve conflict, if presented. Then checkout on main branch and merge feature1: git merge feature1. Then do the same for feature2: git checkout feature2, git rebase master, git checkout master, git merge feature2. Notice that this process better start from clean branches, not already messed-up.

  •  Tags:  
  • git
  • Related