0

So I created a branch from master. lets say this branch is called br1.

I begin to solve issues in this br1.

My coworker is also gonna work on this br1. So he created a branch called br2 from br1.

I am moving forward with br1 on my issues and he is moving forward with br2 on his issues.

enter image description here

At the end, how can we merge br1 and br2 with no conflict ?

om-nom-nom
  • 60,231
  • 11
  • 174
  • 223
ahri
  • 287
  • 1
  • 4
  • 11
  • If you have conflicts with your branchs you need use a mergetool to solve it manually – MrMins Oct 24 '14 at 18:47
  • I dont think we suppose to have conflicts because we are fixing different files..That is my question, I am not sure if I am going to have conflicts – ahri Oct 24 '14 at 18:49
  • After you extended your br2 from br1, did you continue working in the branch br1? – MrMins Oct 24 '14 at 18:53
  • You want to merge both of them to the master, right? Or you want to merge one of them? Or end up only with br1 once your coworker is done? – om-nom-nom Oct 24 '14 at 18:56
  • After I extended br2 from br1, I did continue working on it. MY coworker is working on br2. BUT, we are working on different files – ahri Oct 24 '14 at 20:08
  • @ahri sure, but your last statement is totally unclear: *At the end, how can we merge br1 and br2 with no conflict ?* – om-nom-nom Oct 24 '14 at 20:57

1 Answers1

0

If you are both working on different files, you shouldn't have conflicts when you merge your branches together. Conflicts occur in git when it is not able to programmatically determine what change is supposed to be the one that ones during the merge.

For example:

In your branch, you delete a file. And in the other branch, your coworker modifies it. So what is supposed to be there when the merge is done? Should the file be deleted or does your coworker actually need it in its new form? Hence the conflict. Git is going to ask you, the human, to look at the change and decide what is supposed to be there.

Conflicts are not a BAD THING. Proper organization of your branches will help to minimize them. But they are not something that you need to avoid. Resolving a conflict can be painful sometimes but it is not something that you should worry about. You can also minimize the risk of conflict through regular merging of your branches so that they don't diverge too far from each other.

Schleis
  • 34,455
  • 6
  • 60
  • 79
  • Also, git support different diff algorithms, some of them are smarter than the others (e.g. [patience algorithm](http://stackoverflow.com/a/4045087/298389)) – om-nom-nom Oct 24 '14 at 19:25
  • cool thx. Just wondering, if my coworker and me are changing the same file in different branch which is the case the conflict will occur, and I decided to use his change to that file, how should I select so git will ignore my change and take his change? – ahri Oct 24 '14 at 20:11
  • You can edit the file which will show the lines that git is not sure about marked with `>>>>>`, `========`, and `<<<<<<< – Schleis Oct 24 '14 at 20:19