Using Merge Tools
A merge tool is a graphical (or TUI) program that helps you resolve conflicts by showing the two sides side-by-side and letting you pick hunks with a click instead of editing raw conflict markers. Git ships with git mergetool to launch the configured tool for each conflicted file.
Why use a merge tool
Three-way view — see base, ours, and theirs at the same time. Much clearer than reading markers.
Click to take a side — no risk of accidentally leaving
<<<in the file.Syntax highlighting — easier to read code than plain text.
Inline editing — fix typos and refactor right in the merge view.
Popular merge tools
VS Code — built-in 3-way merge editor (
Open Merge Editorbutton in Source Control). Free.Meld — free, cross-platform, simple. Popular default on Linux.
Beyond Compare — paid, very powerful. Industry favourite.
P4Merge — free part of Perforce. Solid 3-way view.
KDiff3 — free, open-source, cross-platform.
Kaleidoscope — Mac-only, beautiful, paid.
vimdiff / Neovim — terminal-based, no install needed if you already use Vim.
Configuring a merge tool
VS Code
git config --global merge.tool vscode git config --global mergetool.vscode.cmd 'code --wait --merge $REMOTE $LOCAL $BASE $MERGED' git config --global mergetool.keepBackup false
Meld
git config --global merge.tool meld # Meld is auto-discovered on most installs
vimdiff
git config --global merge.tool vimdiff git config --global mergetool.vimdiff.cmd 'vimdiff $LOCAL $MERGED $REMOTE'
Beyond Compare
git config --global merge.tool bc4 git config --global mergetool.bc4.path '/Applications/Beyond Compare.app/Contents/MacOS/bcomp' # macOS
Launching the tool
During a merge with conflicts
git merge feature-x # produces conflicts git mergetool # opens the merge tool for each conflict # Resolve in the GUI, save, close. # Repeat for each conflicted file. git commit # finalise the merge
The four files the tool sees
$BASE— the common ancestor (where the two branches diverged).$LOCAL— your side (the branch you were on before merging).$REMOTE— their side (the branch being merged in).$MERGED— the file Git wants you to produce. Edit this one — it becomes the final content.
VS Code merge editor walkthrough
Open the Source Control panel (Ctrl/Cmd + Shift + G).
Click a conflicted file. The “Open in Merge Editor” button appears at the top.
You see three panes: Incoming (theirs), Current (ours), and Result.
Each conflict has buttons: “Accept Current”, “Accept Incoming”, “Accept Both”.
Edit the Result freely. When done, click “Complete Merge”.
Stage and commit as usual.
Avoiding backup files
By default mergetool keeps .orig backups
# Resolve a conflict in src/app.js — Git creates src/app.js.orig # To turn this off: git config --global mergetool.keepBackup false
Cleaning up .orig files
find . -name "*.orig" -delete # Or add *.orig to your global .gitignore_global
Triggering the tool for a single file
git mergetool -- path/to/specific-file.js
Using a tool that you already have configured
Override the configured tool for one merge
git mergetool --tool=meld
List supported tools
git mergetool --tool-help # Lists every tool Git knows about + which ones are detected on your system