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:

  1. Decide how to combine the changes.
  2. Edit the file to remove conflict markers and keep the correct content.
  3. Stage the resolved file:
    git add <file>
    
  4. 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

ToolDescriptionBest For
Manual EditingEdit files and resolve conflicts yourselfSimple conflicts
git mergetoolLaunches configured diff/merge toolVisual step-by-step resolution
IDE/Git GUI toolsVS Code, JetBrains, GitKraken etc.Interactive resolution
diff3 conflict styleShows base version of conflicting linesUnderstanding original context