Conflict Resolution Tools
When Git cannot automatically resolve differences between branches, you need to step in and resolve conflicts manually or with the help of tools.
1. Manual Resolution
The simplest method is to edit the conflicting files directly.
- Open the file and look for conflict markers:
<<<<<<< HEAD=======>>>>>>> branch-name
Steps:
- Decide how to combine the changes.
- Edit the file to remove conflict markers and keep the correct content.
- Stage the resolved file:
git add <file> - Complete the merge:
git commit
2. Using git mergetool
Git provides built-in support to launch a graphical merge tool.
git mergetool
- This will open your configured diff/merge tool for each conflicted file.
- You can configure your preferred tool using:
git config --global merge.tool <toolname>
Common Tools:
- Meld
- KDiff3
- Beyond Compare
- VS Code (via
code --wait)
3. Visual Merge Tools (GUI)
Many code editors and IDEs offer built-in visual interfaces for resolving conflicts.
Examples:
- VS Code: Shows both versions and lets you accept current/incoming/merged changes.
- JetBrains IDEs: Interactive merge UI for resolving each conflict chunk.
- GitKraken / Sourcetree: Dedicated merge assistants with side-by-side views.
These tools make it easier to visualize changes, especially in large diffs.
4. Diff3 Conflict Style
You can change how Git shows conflicts using the diff3 style.
git config --global merge.conflictstyle diff3
This adds a third section showing the common ancestor version of the conflicting lines.
Example:
<<<<<<< HEAD
color = "blue"
||||||| base
color = "green"
=======
color = "red"
>>>>>>> feature
This can be helpful in understanding where the changes diverged from the original code.
Summary
| Tool | Description | Best For |
|---|---|---|
| Manual Editing | Edit files and resolve conflicts yourself | Simple conflicts |
git mergetool | Launches configured diff/merge tool | Visual step-by-step resolution |
| IDE/Git GUI tools | VS Code, JetBrains, GitKraken etc. | Interactive resolution |
diff3 conflict style | Shows base version of conflicting lines | Understanding original context |