Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git Merging Branch Into Master

Tags:

git

branch

svn

If you have a branch which you forked off of master and then developed your feature in it...when it comes to merging back into master, I've heard 2 different approaches:

  1. First merge master into the feature branch, and then merge the branch back into master.
  2. Merge your branch into master.

Can anyone tell me which method is better and if there's an actual benefit to the first?

Or if there's a better method ?

like image 317
Sev Avatar asked Jan 03 '13 18:01

Sev


1 Answers

Let's say you create feature-sev from master, and meanwhile, I create feature-eric. My branch modifies the same file as yours; in fact, it happens to overlap in a way our git client isn't clever enough to understand. I finish development first and merge my changes in.

In this situation, you're inevitably going to be prompted 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), merging master into the branch and making sure everything looks good, you'll resolve the conflict via a merge commit in feature-sev. If you make any mistakes during resolution, you can roll them back without any direct modification to master. This is good.

If you went with (2), you'll resolve the conflict via a merge commit made directly to master. If you make any mistakes, you will break master. This is bad.

like image 69
Eric Tjossem Avatar answered Sep 30 '22 23:09

Eric Tjossem