Git Merging: How to Resolve Conflicts, Choose Strategies, and Keep Clean History
The dreaded CONFLICT (content): Merge conflict in file.txt. For many developers, seeing this message triggers an immediate spike in heart rate. It feels like you broke something.
Take a deep breath. You didn't break anything. A merge conflict is simply Git throwing its hands up and saying, "Hey, two people changed the exact same line of code, and I am not smart enough to guess which one is right. I need a human."
Here is how to read the Matrix, resolve the conflict, and get on with your day without losing your mind.
- Identify conflicted files:
git status - Open the file and read markers:
<<<<<<< HEAD: Your current branch's version=======: Divider>>>>>>> <branch>: Incoming version
- Resolve: Keep desired lines, delete all marker lines (
<<<<<<<,=======,>>>>>>>). - Finalize:
git add <file>thengit commit(orgit merge --continue).
