Git Tips Slides
PageUp x2: previous · PageDown x2: next · Home: index

Solving Conflicts: Overview

Before solving a complex Git merge conflict, it is convenient to have an overview:

What changed between the base and the remote, and what changed between the base and your local version?

I found no tool which does this, so I use that small Bash script git-conflict-overview.sh.

The script can be used in two ways:

  • standalone: git-conflict-overview.sh path/to/conflicted-file
  • as Git mergetool: git mergetool --tool=conflict-overview

To use it as mergetool, register it once in Git:

git config --global merge.tool conflict-overview
git config --global mergetool.conflict-overview.cmd \
  'git-conflict-overview.sh "$BASE" "$LOCAL" "$REMOTE" "$MERGED"'
git config --global mergetool.conflict-overview.trustExitCode true

If you want the two overview diffs to open in meld, configure your Git difftool like this:

git config --global diff.tool meld
git config --global difftool.prompt false

The script opens two diffs for one conflicted file:

  • BASE vs LOCAL
  • BASE vs REMOTE

At the same time, it opens meld for the three-way merge and writes the result to MERGED.

That gives me a quick overview of what my branch changed and what the upstream branch changed before I resolve the conflict.

If the overview diffs are opened with meld and wmctrl plus xdotool are available, then the script places BASE vs REMOTE on the left half of the screen and BASE vs LOCAL on the right half, so both overview windows together use the full screen.

I use the actual merge UI with meld. See the previous section.

BASE vs LOCAL

BASE vs LOCAL: this shows what changed on my branch compared to the common ancestor.

BASE vs REMOTE

BASE vs REMOTE: this shows what changed on the upstream branch compared to the common ancestor.

git mergetool with meld

git mergetool with meld: after reviewing both diffs, I resolve the conflict in the three-way merge view and save the middle pane.


If you want to test it, use this Git repo (git-tips), then:

git switch dummy-branch-to-create-conflict

git merge dummy-to-merge-to-get-merge-conflict

git mergetool --tool=conflict-overview --no-prompt -- scripts/git-merge-pr-base.sh