What is a merge conflict in Git and how to resolve it without losing changes?

Published on 2026-10-20 by frfrand

How Git conflicts appear, what conflict markers mean, and how to resolve them with tests and without discarding work.

What is a merge conflict in Git and how to resolve it without losing changes?

Short answer: a merge conflict occurs when Git cannot automatically decide how to combine certain changes from two lines of development. It is resolved by editing the file until the correct result remains, without the <<<<<<<, ======= and >>>>>>> markers, testing it and marking it with git add before closing the merge.

It does not mean files have been lost or that someone programmed badly: it means a human decision is needed.

It is common when two people modify the same lines of a file, or when one branch deletes something that another modified.

Two people editing the same sign

Imagine there is a sign that says «We open at 9». One person changes it to «We open at 8» and another writes «We open at 10». There is no correct answer that a machine can infer without knowing the intention.

That is similar to a Git conflict. It can combine many changes without help, but there are situations where showing you the alternatives is safer than inventing a mix.

What does a conflict look like?

A file can end up with markers like these:

<<<<<<< HEAD
horario = "08:00"
=======
horario = "10:00"
>>>>>>> feature/horarios

The first part represents one version and the second another. Those lines should not remain in the final code. Your job is to decide which behavior to keep, or write a third solution that combines the intentions.

Names and labels may vary depending on the operation and tool.

An orderly way to resolve it

  1. Run git status to identify which files need attention.
  2. Open each conflict and understand what each branch was trying to do.
  3. Edit the file until you get a correct result, removing the markers.
  4. Run tests or at least the relevant check.
  5. Use git add file to indicate that you resolved that conflict.
  6. Complete the operation: in a merge, with git commit (or git merge --continue).

It is not enough to get the text to compile: both changes may have incompatible business rules. If one branch added a discount and another modified taxes, combining them without looking can produce incorrect numbers.

Can I automatically keep one version?

There are options that favor one side or the other of the conflict. They can be useful in specific situations, but using them indiscriminately is equivalent to throwing one branch's work in the trash.

The difference between resolving a conflict and hiding it is understanding the result.

What if I want to cancel?

While you are in an ongoing merge operation, git merge --abort can attempt to restore the previous state. Even so, it is advisable to avoid starting complex operations with unsaved local modifications, because it is not always possible to recover any state automatically.

Before merging important changes, make a coherent commit or temporarily save your work deliberately.

How to reduce conflicts in a team

Integrate changes frequently, keep tasks separate when reasonable, and avoid having several people continuously editing the same huge file. Pull requests help discuss the expected behavior before integrating.

A conflict is not automatically anyone's fault. Sometimes it simply indicates that work progressed in parallel.

How is this reflected in ArduMaker?

If an application is deployed from GitHub in ArduMaker, resolve conflicts and check the result before sending the branch used in production. The deploy does not perform merges: it brings the branch with a fast-forward, and if the histories diverge, it leaves the server copy equal to the GitHub branch. That is why a conflict never appears on the server, and a change made manually in that copy does not survive the next deploy. An automatic deploy can only execute the code it received: it does not know what the correct business decision was.

In one sentence: Git can detect when it does not know how to merge changes. Resolving the conflict is deciding the final logic, checking it, and recording the integration.

Frequently asked questions

Is code lost when there is a conflict? No. Git stops the merge and shows you the two versions; nothing is discarded until you decide how the file should look.

How do I keep the single-branch version of a file? With git checkout --ours file (your branch's version) or git checkout --theirs file (the version you are integrating), and then git add file. Use it only if you know the other version adds nothing.

How do I avoid conflicts? By integrating frequently, using short branches, and avoiding having multiple people edit the same block of a large file at the same time.

Sources: Git merge · Merge conflicts in Pro Git.

What is a merge conflict in Git and how to resolve it without losing changes?
  • Git
  • merge
  • conflictos

Keep reading

All articles · VPS plans