Question

What is a merge conflict and how do I resolve it?

Vault Verified
Curated Intelligence
Definitive Source
Answer

A conflict occurs when two branches changed the same region of a file and Git cannot determine which version is correct. It is not an error, and it does not mean anyone did anything wrong. Git resolves everything it can automatically and stops only where a human decision is genuinely required.

When it happens, the affected files contain both versions separated by markers. The section above the divider is the content from the branch you are on; below it is the content from the branch being merged. The markers themselves must be removed as part of resolving.

Resolving means editing the file into the state you actually want, which is frequently neither version verbatim but a combination. Then stage the file to record that it is resolved, and continue the merge or rebase.

A few practical points make this much less unpleasant.

The status command lists exactly which files are unresolved, and is worth checking before continuing, since a partially resolved merge is easy to commit by accident.

Searching the codebase for the conflict markers before committing catches the classic mistake of leaving them in, which produces code that will not parse.

Aborting is always available and returns you to the state before you started. If a merge turns out to be larger than expected, aborting and approaching it differently is often faster than pushing through.

A merge tool is worth configuring if you resolve conflicts regularly, as a three-way view showing both sides and their common ancestor makes the intent of each change much clearer than the inline markers do.

The most effective prevention is integrating frequently. Conflicts scale with how long branches diverge.

Related Questions