Merge Conflict

You might say

After pulling, Git stopped with a conflict. Which file do I open, and which section do I change?

When the same content was changed differently on two branches, Git cannot choose and a person must decide what to keepWhen Git cannot automatically reconcile changes while merging main and feature/new-nav—for example, both changed the same heading in index.html—it pauses and writes both versions with conflict markers. Review the surrounding page and understand each branch's intent, then choose or reconcile the heading while retaining the other branch's needed navigation. Remove the markers, finish the merge, and reopen the page to verify the result. Markers do not say which side is correct.
Know first
Merge Conflict
Heading conflict · index.html
<<<<<<< HEAD (main) <h1>Xiaoli's homepage</h1> ====== <h1>Xiaoli's photography homepage</h1> >>>>>>> feature/new-nav
Outside the markersFeature navigation · main contact content
Resolved index.html
<nav>Work About</nav> <h1>Xiaoli's photography homepage</h1> <p>Contact Xiaoli</p>
my-first-page.example

Xiaoli's photography homepage

Contact Xiaoli

After removing the markers, the page shows the final heading, feature navigation, and main's existing contact content.

When to use it

  • Find the conflicted files and open them
    $ git statusboth modified: index.htmlOpen this file first, then search the conflict markers
  • Keep the correct result after understanding both sides
    <h1>Xiaoli's photography homepage</h1>
    <p>City collection</p>
    Each side changed a part; merge into one version when both are needed
  • Stage and commit only after markers are gone
    $ git add index.html$ git commit[main 3f9c2ab] Merge branch feature/new-navCommit only after the markers are gone
  • Rerun the project to confirm both sides still work
    Conflict resolved→Open the page→Heading correct ✓
    Rerun to confirm both sides' changes are still there

When NOT to use it

  • Commit with any conflict marker left in the file
    <<<<<<< HEAD
    <h1>Xiaoli's homepage</h1>
    Markers left in the file break page parsing
  • Delete a whole section without reading the other side
    The heading bug the other side just fixed gets deleted tooDeleting a whole section without reading the other side may drop needed fixes
  • Treat git merge --abort as resolution: it only returns to the pre-merge state, leaving changes unmerged
    git merge --abort→All changes remain unmerged
  • Mix unrelated edits into the conflict resolution
    Changed styles and copy while resolving the heading conflictThis commit mixes unrelated changes, hard to revert and review
Anatomy
<<<<<<< HEAD (main) <h1>Xiaoli's homepage</h1> ======= <h1>Xiaoli’s photography homepage</h1> >>>>>>> feature/new-nav
Below HEAD is this line on the branch you are currently on.
This part came from the current branch; its source marker does not mean the whole section should be kept. Check the page context.
The divider between the two versions; delete it with the markers.
This part came from the branch being merged; check what it does because the source marker does not say whether it is right.
Marks which branch this content came from, for traceability.
Variants
Use needed content from one side
<h1>Xiaoli’s photography homepage</h1>
After confirming one side's change is no longer needed, remove that content
Combine both
<h1>Xiaoli’s photography homepage</h1><p>City collection</p>
Combine useful changes from both sides into the result the page needs
merge --abort
git merge --abort
When the conflict is too tangled, return to the pre-merge state
Typical use cases
Merge pauses
zsh — my-first-page
$ git merge feature/new-navAuto-merging index.htmlCONFLICT (content): Merge conflict in index.htmlAutomatic merge failed; fix conflicts and then commit the result.
Title markers and changes from both branches
index.html · title conflict1 section to resolve
<nav>Work About</nav> ← added by feature/new-nav
<<<<<<< HEAD (main)
<h1>Xiaoli’s homepage</h1>
=======
<h1>Xiaoli’s photography homepage</h1>
>>>>>>> feature/new-nav
<p>Contact Xiaoli</p> ← existing main content

The markers surround the two headings; the navigation outside them still needs to be retained.

Review status and branch context
zsh — my-first-page
$ git statusYou have unmerged paths.both modified: index.html$ git diff -- index.htmlmain: original heading and contact contentfeature/new-nav: photography heading and new navigation
Final file and rendered heading
Resolved index.html · merge commit complete
<nav>Work About</nav> <h1>Xiaoli’s photography homepage</h1> <p>Contact Xiaoli</p> [main 3f9c2ab] Merge branch feature/new-nav
my-first-page.example

Xiaoli’s photography homepage

Contact Xiaoli

Markers are gone. The page shows the final heading, the feature branch navigation, and main’s existing contact content.

Further reading