Course contentsShow
← Data Science
Lesson 2017 of 2,14546. Version Control with GitFree lesson

Understanding Merge Conflicts

Learn what causes merge conflicts, how Git marks them in files, and the anatomy of conflict markers.

Understanding Merge Conflicts

You'll learn what causes merge conflicts, how Git marks them, and how to read the conflict markers in your files.

What Causes Merge Conflicts?

A merge conflict occurs when Git cannot automatically reconcile differences between two branches. This typically happens when:

  • Two branches modify the same lines in the same file
  • One branch deletes a file while another modifies it
  • Changes affect adjacent lines in complex ways

Think of it like two editors making contradictory changes to the same paragraph in a document—someone needs to decide which version (or combination) to keep.

How Git Marks Conflicts

When a conflict occurs during a merge, Git stops and marks the conflicting sections directly in your files. It doesn't make the decision for you; instead, it shows you both versions and asks you to choose.

The Anatomy of Conflict Markers

Git uses special markers to delineate the conflicting sections:

<<<<<<< HEAD
This is the content from your current branch
=======
This is the content from the branch being merged in
>>>>>>> feature-branch

Breaking it down:

  • <<<<<<< HEAD marks the start of the conflict and indicates your current branch's version follows
  • ======= separates the two conflicting versions
  • >>>>>>> feature-branch marks the end and shows which branch the alternative content comes from

Everything between <<<<<<< HEAD and ======= is what exists in your current branch. Everything between ======= and >>>>>>> is what's coming from the other branch.

Your job is to manually edit the file, remove the markers, and keep (or combine) the content you want.

Key Takeaway: Merge conflicts occur when Git can't automatically reconcile changes to the same lines; Git marks conflicts with <<<<<<<, =======, and >>>>>>> markers, leaving you to manually resolve which content to keep.