Search code examples
gitgithubgitlabgit-merge-conflict

Git Branch and Fork Questions - Conflicts


Trying to figure out what happens in particular cases when there are multiple branches and/or a fork off of a master branch and how that might cause conflicts.

Say I have the following case where black is the master branch, red is a branch, and green is a branch:

enter image description here

The green branch occurs after the red branch and is merged back into main before red. When red is merged - will there be conflicts?

Now say that red is a branch but green is a fork. Red branches before green is forked. Green has makes code changes and then sends a pull request to the master, who accepts and imports changes. the red merges back into main. Will there be conflicts in that case?

Thanks in advance.


Solution

  • The answer is neither yes nor no, but it depends.

    A conflict occurs when two developers, regardeless of the branch in which they operate, change the same line of code, or a file is deleted by one, but changed by the other.

    In this article at https://www.atlassian.com/git/tutorials/using-branches/merge-conflicts#:~:text=Conflicts%20generally%20arise%20when%20two,automatically%20determine%20what%20is%20correct.&text=Git%20will%20mark%20the%20file,and%20halt%20the%20merging%20process. you may find a lot of information about this topic.