Git merge branch into master

If you have a branch that you separated from the master, and then developed your function in it ... when it comes to merging with the master, I heard two different approaches:

  • First merge the master into a function branch, and then merge the branch back into the master.
  • Combine your branch into a master.

Can someone tell me which method is better and if there is an actual advantage for the first?

Or if there is a better method?

+7
source share
3 answers

Say you create a sev function from the wizard, and meanwhile I create an eric function. My branch modifies the same file as yours; in fact, this happens with overlapping, as our git client is not smart enough to understand. First I finish the development and merge my changes.

In this situation, you will inevitably be asked to resolve the conflict.

CONFLICT (content): Merge conflict in stackoverflow.html Automatic merge failed; fix conflicts and then commit the result. 

If you went with (1), combining the wizards into a branch and making sure everything looks good, you will resolve the conflict by merging in the -sev function. If you make errors during resolution, you can roll them back without any direct modification to the wizard. It's good.

If you went with (2), you will resolve the conflict through a merger made directly with the master. If you make any mistakes, you will violate the wizard. This is bad.

+2
source

I think it depends; -)

Some things to consider:

  • Do you need a function branch after merging? If so, it may be useful to combine master into it, as well as merge back into master . If not, it doesn't make much sense to merge with the function branch if you delete it anyway.
  • Is it possible to break the local working copy of the master branch? If not, you should avoid combining code into master , which can lead to a lot of conflicts that need to be resolved manually. If everything is in order, continue.

In general, I would say it depends on how you work with git.

Since I usually use property branches only temporarily, and I delete them after the function completes successfully and merge them into master , I usually merge directly into master and delete the other branch later.

On the other hand, I can imagine that there may be situations where it may be useful to do it the other way around. But until there are good reasons, I will try to avoid this. One merge is enough :-).

+1
source
Theoretically, there is no difference. You have a set of changes in one branch that you combine with a set of changes in another branch. No matter where these changes end.

In practice, it is better to merge the changes into property branches, as this gives you an isolated place to resolve conflicts. This is especially important if the feature branch has been under development for a long time, since subtle conflicts often arise that will be resolved after the first commit.

The best approach is to regularly update from the leading branch of the function, which reduces the likelihood of conflicts at the end of the development of functions.

+1
source

All Articles