Web apps & software

What is a merge conflict?

A merge conflict happens when two branches edit the same part of a file in different ways, or one deletes a file the other changed, and Git cannot decide automatically which version to keep.

What you see

Git marks the file with <<<<<<<, ======= and >>>>>>> lines around the two competing versions and stops the merge. A person reads both, writes the correct combined result, removes the markers, and commits.

Why they happen

Long-lived branches drift away from main, two people work on the same screen, or a large automatic reformat touches every line. The longer branches live apart, the bigger the clash.

Reducing them

  • Merge or rebase from main often.
  • Keep branches short-lived and changes small.
  • Split big files so people rarely edit the same one.
  • Agree on a formatter so style changes do not conflict.
  • Talk before two people refactor the same module.

Resolve carefully

A conflict resolved without understanding either side can silently drop a fix. After resolving, run the tests, and ask the authors of both changes if unsure. Visual merge tools in editors make the choices easier to see.

Questions, answered

No. It is a normal result of parallel work.

Yes, in any text file, and lock files and spreadsheets exported as text are frequent offenders.

By the Stegnor team · Updated