Every now and then you may encounter a merge conflict in GitHub for Mac while syncing or merging branches.
This happens when two branches have changed the same part of the same file, and then those branches are merged together. For example, if you make a change on a particular line in a file, and your colleague working in a repository makes a change on the exact same line, a merge conflict occurs. Git has trouble understanding which change should be used, so it asks you to help out.
When GitHub for Mac detects a conflict it will prompt you to manually resolve it. The word "CONFLICT" appears next to the conflicted file in the Changes view:
Use your text editor of choice to open the file in which the conflict has occurred, and you'll notice that Git has automatically added conflict markers to the affected areas.
Tip: You can quickly open the conflicted file in your default text editor simply by double-clicking on the filename in the list of uncommitted changes.
A conflict-marked area begins with <<<<<<<
and ends with >>>>>>>
. These are also known as the conflict markers. The two conflicting blocks themselves are divided by a =======
.
In this example, the words original
and modified
have changed in the exact same sentence. You'll need to decide whether or not you want to pick the block above the =======
, the block below it, or create a new solution altogether (which might contain a little of each change). The goal is to get the file to look exactly how you want it.
Once you've resolved the conflict, make sure that you've removed all the remaining conflict markers and save your changes. Then, make another commit to finish resolving it.