LinuxCommandLibrary

git-mergetool

Resolve git merge conflicts with external tools

TLDR

Launch the default merge tool to resolve conflicts

$ git mergetool
copy

List valid merge tools
$ git mergetool --tool-help
copy

Launch the merge tool identified by a name
$ git mergetool [[-t|--tool]] [tool_name]
copy

Don't prompt before each invocation of the merge tool
$ git mergetool [[-y|--no-prompt]]
copy

Explicitly use the GUI merge tool (see the merge.guitool configuration variable)
$ git mergetool [[-g|--gui]]
copy

Explicitly use the regular merge tool (see the merge.tool configuration variable)
$ git mergetool --no-gui
copy

SYNOPSIS

git mergetool [options] [pathspec...]

PARAMETERS

--tool=
    Use specified merge tool (overridable by .gitattributes).

--tool-help
    List available merge tools.

--[no-]prompt
    Whether to prompt before each merge (default: true).

--[no-]gui
    Prefer GUI tool if available.

--diff-mode
    Launch diff tool on two files instead of merge.

--base
    Base file as "local" for three-way merge.

--ours
    Ours version as "remote".

--theirs
    Theirs version as "remote".

--stdout
    Write merged result to stdout.

--list-tools
    List configured merge tools.

--abort
    Abort current in-progress merge.

--quit
    Quit tool on successful merge.

--extcmd=
    Use command string as merge tool.

--no-index
    Ignore .gitattributes index info.

--ignore-missing
    Ignore missing files from either side.

--ignore-submodules
    Ignore unmerged submodules.

-O
    Process only specified file.

-t
    Shorthand for --tool=.

DESCRIPTION

git mergetool launches external graphical or console-based merge tools to visually resolve conflicts during Git merges, rebases, or cherry-picks. When Git cannot auto-merge changes, it leaves conflict markers in files. This command identifies conflicted files and opens them in a configured tool, providing side-by-side views of $LOCAL (your version), $REMOTE (incoming version), $BASE (common ancestor), and $MERGED (working tree file).

Supported tools include vimdiff, gvimdiff, kdiff3, tkdiff, xxdiff, meld, opendiff, emerge, and custom ones via git config. Default tool is OS-dependent (e.g., opendiff on macOS, vimdiff on Linux).

After editing in the tool, save and exit: exit code 0 marks the file resolved; otherwise, Git prompts again. Use --no-prompt to skip prompts. Configure tools with git config mergetool.<tool>.cmd and merge.tool <tool>. Ideal for complex conflicts where git mergetool automates file handling and progress tracking.

CAVEATS

Does not merge automatically; requires external tools installed and configured. Exit code 0 from tool indicates resolution. May create temporary files in $GITMERGETOOL_TEMP_DIR.

TEMPORARY FILES

Tool receives $LOCAL, $REMOTE, $BASE, $MERGED; edit $MERGED and exit.

CONFIGURATION

Set merge.tool, mergetool.<tool>.cmd, mergetool.<tool>.trustExitCode.

HISTORY

Introduced in Git 1.5.3 (Feb 2007) for basic tool support; expanded in Git 1.6+ with more tools, prompts, and options like --diff-mode (1.7.2). Evolved with Git ecosystem for better conflict handling.

SEE ALSO

git-merge(1), git-difftool(1), git-config(1), gitattributes(5)

Copied to clipboard