Recent chats
ASKGEEZ Q&A GUIDETechnology & devices

How do I read Git conflict markers when two branches change the same lines?

Quick answer

In a typical Git merge conflict, <<<<<<< begins the current-side text, ======= separates it from the other-side text, and >>>>>>> marks the end of that other-side section. These are competing edits, not a completed answer. Choose or combine the intended content, remove every conflict marker, review the resulting file, and then stage the resolved file. The labels and marker style can vary with the merge context and configuration. [S1]

LET’S WORK THROUGH IT

The question, the details, the next step.

Question

I opened a file after a merge conflict and see lines starting with <<<<<<<, =======, and >>>>>>>. What am I looking at?

Geez

Those lines bracket competing versions of part of the file. In Git’s usual textual conflict-marker style, the text after <<<<<<< is from the current side; the text after ======= is from the other side, and >>>>>>> closes that section. The markers help you locate the conflict, but they are not the intended final content. You must decide what the file should contain and edit it accordingly. [S1]

For example, suppose the conflicted file contains:

<<<<<<< current side
color = "blue"
=======
color = "green"
>>>>>>> other side

Assume the labels are placeholders and the two values are the competing edits. The resolved file might keep color = "blue", keep color = "green", or use a different result that combines the intended changes. The example does not tell you which choice is right; that depends on the project’s intended behavior.

Follow-up question

Does the first section always mean my branch, and the second section always mean the branch I’m merging in?

Geez

For a typical merge, think of the first section as the current side and the second as the other side. Git’s merge documentation describes the current side as the current HEAD and the other side as the other branch’s MERGE_HEAD. But don’t rely on a casual reading of “mine” and “theirs” if you are unsure which operation or labels produced the conflict: side labels and marker style depend on merge context and configuration. [S1]

A merge can also have a common ancestor version recorded in the index. That base version is not shown in the usual two-section marker style. A diff3 or zdiff3 style can include a base section as well, which gives you another point of comparison. [S1] If you see extra markers, read the exact format in front of you rather than assuming every conflict has only two visible alternatives.

Follow-up question

How do I decide what to keep instead of just choosing one side?

Geez

Compare each alternative with the surrounding code or text and the purpose of both edits. Ask: What was each change trying to accomplish? Can both goals be preserved in one final version? Does the surrounding content still make sense after the conflict is removed? If you cannot establish the intended result from the file and your project context, ask the relevant teammate or maintainer rather than guessing.

Continuing the illustrative example, suppose one side changes the default color and the other changes a label that is not shown in the snippet. If those edits affect separate lines, a sensible resolution might preserve both—but this small example does not establish that they are compatible. Inspect enough surrounding content to understand the actual change. Treat the sample as a reading aid, not a rule that one side wins.

Follow-up question

What should I do once I’ve edited the conflict, and how can I check that I’m done?

Geez

Read the whole edited section as the file should look after the merge. Confirm that you made the intended choice or combination, that no conflict markers remain in the resolved section, and that the surrounding content is coherent. Then stage the resolved file; Git’s merge documentation describes editing the file to the intended final content, removing the markers, and staging the result. [S1] For example, a staged-file command might be git add path/to/file; replace the path with your actual file. Staging records the resolution for the merge, but it does not establish that your chosen content is behaviorally correct.

Annotated resolution

# Before: competing edits, not a finished result
<<<<<<< current side
color = "blue"
=======
color = "green"
>>>>>>> other side

# After: illustrative choice only
color = "blue"

The after-version is appropriate only if blue is the intended final value. If neither alternative is right on its own, edit the file to the intended combined result. The markers themselves do not decide what the code or content ought to be.

A practical checklist

  • Identify the current-side and other-side sections using the markers; treat labels as context-dependent.

  • Compare both edits with the surrounding file and the purpose of the changes.

  • Choose or combine content based on the intended final result, not on marker order alone.

  • Remove the conflict markers and reread the resolved section in context.

  • Stage the resolved file after reviewing it; staging is not proof that the result is correct.

A few more useful answers

What does `=======` mean in a conflict?

It separates the current-side section from the other-side section in Git’s usual textual conflict-marker style. It is a divider, not a choice or a final line of content. [S1]

Why does my conflict show a base version too?

Git can show the common-ancestor base in diff3 or zdiff3 marker styles. That extra section is for comparison; you still need to edit the file to the intended final content. [S1]

Do the markers tell me which version is correct?

No. They identify competing content, but do not establish which change is intended. Use the surrounding context and project requirements to decide, and ask a maintainer if the purpose is unclear.

Sources

References used for this guide.

  1. [S1] Git - git-merge Documentation
    git-scm.com · Checked

YOUR QUESTION. YOUR DETAILS.

Let’s work through your situation.

Get a tailored answer or help with your next task. Starts at $1, with a quote before you pay.

Ask your own question
← Back to Geez at Work