Resolving Merge Conflicts Step-by-Step with Conflict Markers0%

Resolving Merge Conflicts Step-by-Step with Conflict Markers

Beginner12 min read•Updated: Jul 11, 2026
Study MaterialsCheatsheet

Resolving Merge Conflicts Step-by-Step with Conflict Markers

Merge conflicts are not software bugs or Git errors—they are a natural, protective feature of version control. When two developers change the exact same lines of the same file in different ways, Git refuses to guess which version is correct and safely halts, asking the developer to resolve the conflict.


1. What Causes a Merge Conflict?

A conflict occurs when:

  1. 1
    Developer A and Developer B branch from the same base commit.
  2. 2
    Developer A edits line 15 in server.js and commits it to main.
  3. 3
    Developer B edits line 15 in server.js in a conflicting way on feature-branch.
  4. 4
    When merging feature-branch into main, Git encounters conflicting modifications on line 15 and pauses the merge:
Output
Auto-merging src/server.js
CONFLICT (content): Merge conflict in src/server.js
Automatic merge failed; fix conflicts and then commit the result.

2. Anatomy of Git Conflict Markers

Git opens the conflicting file and marks the disputed lines with special ASCII delimiter markers:

JavaScript
<<<<<<< HEAD
const PORT = process.env.PORT || 8080; // Main branch setting
=======
const PORT = process.env.PORT || 5000; // Feature branch setting
>>>>>>> feature-backend

Breakdown of the Markers:

  • <<<<<<< HEAD : Marks the beginning of the conflicting section. Shows the version on the branch you are currently standing on (main).
  • ======= : The divider separating the two competing versions.
  • >>>>>>> feature-backend : Marks the end of the conflict section and identifies the incoming branch that introduced the alternative.

3. The 4-Step Method to Resolve Conflicts

Step 1: Identify Conflicted Files

Run git status to see which files have unresolved conflicts (listed under "Unmerged paths"):

Bash / Terminal
git status
# Output: both modified: src/server.js

Step 2: Open and Edit the Conflicting File

Open src/server.js in your text editor (such as Visual Studio Code). Decide how the code should look:

  • Keep the HEAD version?
  • Keep the incoming version?
  • Combine ideas from both versions?

Critical Rule: You must completely delete all <<<<<<<, =======, and >>>>>>> lines from the file!

Cleaned resolution:

JavaScript
// Clean resolved code
const PORT = process.env.PORT || 8080;

Step 3: Stage the Resolved File

Staging the file informs Git that the conflict has been resolved:

Bash / Terminal
git add src/server.js

Step 4: Finalize the Merge Commit

Bash / Terminal
git commit

Git will pre-populate a standard merge commit message: Merge branch 'feature-backend' into main. Save and exit the editor. Your merge is now complete!


4. Aborting a Merge (--abort)

If a merge is overwhelming or you started it by mistake, you can reset your working tree back to the state before the merge was attempted:

Bash / Terminal
git merge --abort

This safely rolls back the merge without losing any previous work.


Interactive Quiz

Practice Quiz

Question 1
When does a Git merge conflict occur?
Question 2
In Git conflict markers, what does the content between <<<<<<< HEAD and ======= represent?
Question 3
What must a developer do with the markers (<<<<<<<, =======, >>>>>>>) when resolving a conflict?
Question 4
After manually editing a conflicted file and removing conflict markers, how do you signal to Git that the conflict is resolved?
Question 5
How can a developer abort an in-progress merge and return the repository to its pre-merge state?
Next Lesson

What is GitHub? Remote Hosting, Social Coding & Open Source

Continue learning with hands-on practice, examples, and exercises in the upcoming topic.

Practice Quiz

Test your understanding of this lesson with 5 questions. Each question has one correct answer.

PrevNext