Course contentsShow
← Computer Science
Lesson 2187 of 2,87249. Version Control with GitFree lesson

Merge Conflicts: Basics

Learn why merge conflicts occur when Git cannot automatically reconcile changes between branches.

Merge Conflicts: Basics

You'll learn why Git sometimes can't automatically merge your branches and requires human intervention.

When you merge two branches, Git tries to automatically combine their changes. But sometimes Git encounters a problem: the same part of the same file was modified differently in both branches. Git doesn't know which version is correct, so it stops and declares a merge conflict.

Why Conflicts Happen

Imagine two editors working on the same sentence in a document. One changes it to "The cat is fast" while the other changes it to "The cat is fluffy." When they try to combine their work, which version should win? Neither editor can decide for the other—they need to talk and agree.

Git faces the same dilemma. When you've changed line 42 of app.js in your feature branch, and someone else changed that exact same line in the main branch, Git cannot automatically reconcile these competing edits. Both changes touch the same "location" in the codebase.

What Triggers a Conflict

Conflicts occur during merges (both fast-forward impossible scenarios and three-way merges) when:

  • The same lines in the same file were edited differently in both branches
  • One branch modified a file while another deleted it
  • Both branches created files with the same name but different content

Git will successfully auto-merge changes to different parts of a file, or changes to different files entirely. Only overlapping edits cause conflicts.

Key Takeaway: Merge conflicts happen when Git cannot automatically decide between competing changes to the same part of a file—human judgment is required to resolve which version (or combination) is correct.