Synopsis
git mergetool [-t <tool>] [--tool-help] [<file>...]
Description
The git mergetool command launches an external merge tool to help resolve conflicts after a merge, rebase, or cherry-pick stops with conflicts. Common tools include vimdiff, meld, kdiff3, p4merge, opendiff, and vscode. Once configured via merge.tool, running git mergetool opens each conflicted file in the chosen tool and stages the resolution when you save.
Most modern editors (VS Code, JetBrains IDEs, Vim with Fugitive) have built-in merge UIs that make git mergetool redundant. Still, on the command line or over SSH, it remains an essential utility for graphical or three-pane conflict resolution.
In day-to-day use, git mergetool integrates closely with shell aliases, editor plugins, and continuous integration. Power users often add aliases that combine flags they always pass, or wrap the command in scripts that enforce team conventions. Output formatting can be customized via Git config — pretty formats, color schemes, and pager behavior are all tunable. When something goes wrong, the first diagnostic step is usually to re-run the command with GIT_TRACE=1 in the environment, which reveals the underlying plumbing calls. For unusual situations, the --help output (git mergetool --help) opens the full manual page with details on every option, including those rarely used in casual workflows but essential for debugging or scripting at scale.
Understanding how git mergetool interacts with the rest of Git's data model — the object database, the index, refs, and the working tree — pays dividends. Each command operates on some subset of these pieces, and knowing which it touches helps predict outcomes and recover from mistakes. Reading the official Git documentation alongside hands-on practice in a throwaway repository is the fastest way to internalize the nuances. Most production issues with Git stem from one of three causes: surprising default behavior, partial network operations, or rewriting history that was already shared. A working mental model of git mergetool's side effects helps avoid all three.
Common Options
| Option | Description |
|---|---|
-t <tool>, --tool=<tool> | Use a specific merge tool for this run. |
--tool-help | List the merge tools Git knows about. |
-y, --no-prompt | Don't prompt before launching the tool. |
-g, --gui | Use the GUI tool from merge.guitool. |
-O<file> | Process files in the order listed in file. |
Examples
git config --global merge.tool meld
# Configure meld as the default
git mergetool
# Launch the configured tool on each conflicted file
git mergetool -t vimdiff
# Use vimdiff just this once
git mergetool --tool-help
# See the list of supported tools
Common Mistakes
After resolving with git mergetool, leftover .orig backup files clutter the directory. Disable them with git config --global mergetool.keepBackup false. Another pitfall: launching a GUI tool over SSH without X forwarding fails silently. Configure a console-friendly tool (like vimdiff) for remote sessions.
Related Commands
git merge, git rebase, git config, git diff