0

I've just recently started using Git, I'm working on my own and I'm still learning how it all works.

A potential issue I'm wondering about is if the same file is being worked on in two branches at once. For example a style sheet.

Say a new page for a website is being developed in branch1, and a second in branch2. Both have been complete with the relevant css added to style.css, and need to be merged to master.

If branch1 is merged then the stylesheet in master would be updated with the new styles. But then if branch2 is merged after wouldn't the css added in branch1 be overwritten?

Is there some way around this?

Edit:

I have tested this by creating a test.txt file:

hello world

Then created branch1 and edited the file to:

hello world

added change test1

Then created branch2 from master and similarly edited to:

hello world

added change test2

I merged branch1 into master without issue. But when I tried to merge branch2 I get a conflict error. Fix conflicts and then commit the results.

What would be the best way to correct this? Would I just start branch2 from scratch with the branch1 changes?

Edward144
  • 467
  • 1
  • 5
  • 14

2 Answers2

0

In short, when branch2 is merged, it would be merged with result of branch1 + master merge, so changes from branch1 won't get lost - they will be part of merge.

In practice you will get a merge conflict that you need to then resolve.

eis
  • 51,991
  • 13
  • 150
  • 199
0

in this case, the second merge will conflict, must modify it to merge

mayudong1
  • 1
  • 1