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
mainhas:
color = "blue"
- Branch
featurechanges 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
mainmodifiesconfig.js - Branch
cleanupdeletesconfig.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
refactorrenamesapp.jstocore.js - Branch
deveditsapp.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 Type | Cause | Resolution |
|---|---|---|
| Same Line Edits | Both branches edit same line | Manual merge |
| Deletion vs. Modification | One deletes, one edits a file | Decide to keep or delete |
| Rename and Edit | Rename in one, edits in another | Apply changes to renamed file manually |