Merge Conflict
When version control cannot automatically combine changes because different branches modified the same code incompatibly.
Also known as: Git Conflict, Merge Conflict Resolution, Resolving Merge Conflicts
Category: Concepts
Tags: software, version-control, git, collaboration, problem-solving
Explanation
A merge conflict occurs in version control when Git cannot automatically reconcile changes because different branches modified the same lines of code in incompatible ways. Resolving merge conflicts requires manually deciding which changes to keep, combining them, or creating an entirely new solution.
When Git encounters a conflict during merge or rebase, it pauses the operation and marks the conflicted sections in the files. Each conflict shows both versions with conflict markers: `<<<<<<< HEAD` shows your current changes, `=======` separates them, and `>>>>>>> branch-name` shows the incoming changes. You must edit the file to resolve the conflict, remove the markers, stage the resolved file, and complete the merge.
Good conflict resolution requires understanding both sets of changes: what problem each was solving and whether they're compatible. Sometimes you keep one version, sometimes the other, sometimes both (if they're independent), and sometimes neither—you create a third solution that addresses both concerns. This requires technical understanding and often communication with the other authors.
Strategies to minimize conflicts include: committing and merging frequently (creating smaller conflicts), coordinating who works on what files, refactoring to reduce code interdependencies, and using feature toggles to isolate changes. However, some conflicts are inevitable in collaborative work and represent genuine tensions between different approaches that require human judgment.
Merge tools and IDE integrations make conflict resolution easier by providing visual diffs, 3-way merge views, and semantic understanding of code. Despite automation, the decision of how to resolve conflicts ultimately requires human understanding of the code's purpose.
Related Concepts
← Back to all concepts