Common Conflict Scenarios

Git merge conflicts typically arise when changes in two branches cannot be automatically reconciled. Below are some of the most common scenarios that cause merge conflicts and how to recognize them.


1. Same Line Edits

Two branches modify the same line of the same file.

Example:

  • Branch main has:
color = "blue"
  • Branch feature changes it to:
color = "red"

When merged, Git doesn’t know which version to keep.

Conflict Marker:

<<<<<<< HEAD
color = "blue"
=======
color = "red"
>>>>>>> feature

Resolution:

Choose one or combine the lines and remove the conflict markers.


2. File Deletion vs. Modification

One branch deletes a file while another modifies it.

Example:

  • Branch main modifies config.js
  • Branch cleanup deletes config.js

When merging, Git doesn't know whether to keep the changes or honor the deletion.

Resolution Options:

  • Keep the file (and the changes)
  • Accept deletion and remove it

You must decide which direction makes sense for your repo.


3. Renaming and Editing

One branch renames a file while another makes changes to it.

Example:

  • Branch refactor renames app.js to core.js
  • Branch dev edits app.js

Git can’t track both the rename and the change automatically.

Resolution:

  • Manually apply the changes to the renamed file
  • Stage and commit the result

Summary

Conflict TypeCauseResolution
Same Line EditsBoth branches edit same lineManual merge
Deletion vs. ModificationOne deletes, one edits a fileDecide to keep or delete
Rename and EditRename in one, edits in anotherApply changes to renamed file manually