Workflow & Tools
Merge Conflicts
I used to break out in a cold sweat whenever I encountered a merge conflict. Today I know: Git isn't broken – it's just asking for my opinion.
In an ideal world, we work on projects alone and everything flows together perfectly. But in reality, we work in teams or on different features simultaneously. Git usually tries like a magical assistant to automatically weave all changes together.
A merge conflict is the moment when this assistant stops and says: "Hey, I don't know which version is correct." It's not an error that destroys your project, but an invitation from Git to make a conscious decision.
1. Triggering the Conflict
A conflict always occurs when Git can't automatically merge two changes at the same location. Try it here – start the merge and see how Git reacts:
Don't panic: Git hasn't overwritten anything. The state is 'frozen' until you decide how to proceed.
2. Understanding & Resolving the Markers
Git marks the affected areas directly in the code. HEAD refers to your current code, while Incoming are the changes from the other branch.
3. Completing the Merge
Once you've removed the markers in the editor (or clicked 'Accept'), you need to tell Git you're done. This happens in two simple steps:
git add .
git commit -m 'chore: resolve merge conflict'Never commit blindly. Always check that the file still has valid syntax after removing the markers.
If it gets messy: With git merge --abort you can undo everything and cancel the merge completely.