git-mergetool
Resolve git merge conflicts with external tools
TLDR
Launch the default merge tool to resolve conflicts
List valid merge tools
Launch the merge tool identified by a name
Don't prompt before each invocation of the merge tool
Explicitly use the GUI merge tool (see the merge.guitool configuration variable)
Explicitly use the regular merge tool (see the merge.tool configuration variable)
SYNOPSIS
git mergetool [
PARAMETERS
-t
Specify the merge tool to use. If not specified, Git will try to launch a configured default tool or one from a predefined list.
-y, --no-prompt
Do not prompt before invoking the merge tool for each file. Automatically launch the tool for all conflicted files.
--prompt
Prompt before invoking the merge tool for each file (default behavior).
--tool-help
Display a list of merge tools supported by your Git installation, and exit.
--[no-]gui
Use the GUI version of the merge tool if available (--gui
), or specifically avoid GUI tools (--no-gui
).
--[no-]trust-exit-code
Trust the exit code of the merge tool to determine if the resolution was successful. If --no-trust-exit-code
, Git will always prompt for confirmation.
--[no-]recurse-submodules
Recursively resolve conflicts in submodules (--recurse-submodules
) or not (--no-recurse-submodules
). Defaults to what merge.recurseSubmodules
is set to.
Optional path(s) to specific conflicted file(s) to resolve. If omitted, git-mergetool will iterate through all conflicted files.
DESCRIPTION
git-mergetool is a convenience command that helps you resolve merge conflicts by launching an appropriate visual merge tool. When a Git merge results in conflicts, Git marks the conflicted files. Instead of manually editing these files to resolve the differences, git-mergetool automates the process of calling an external GUI-based or terminal-based merge tool to guide you through the resolution. It iterates through each conflicted file, presenting the conflicting versions (local, remote, and common ancestor) and allowing you to interactively choose, combine, or edit the desired outcome. After you resolve a file in the tool, git-mergetool often prompts you to confirm resolution and removes temporary files created by the merge tool. It relies on external tools (like KDiff3, Meld, Beyond Compare, etc.) which must be installed and configured with Git.
CAVEATS
git-mergetool is a wrapper that requires external merge tools to be installed on your system. It does not perform the merge logic itself but simply orchestrates the calls to these tools.
Proper configuration via git config
is often necessary to ensure Git knows how to find and use your preferred merge tools.
Always review changes made by the merge tool before marking a conflict as resolved and committing, as automated merges can sometimes introduce unintended regressions.
TYPICAL WORKFLOW
1. Perform a merge: git merge <branch>
2. If conflicts occur, Git reports them.
3. Launch the merge tool: git mergetool
4. Resolve conflicts interactively within the external tool for each file.
5. After resolving a file, save changes and close the tool. git-mergetool will usually remove the temporary *.orig
file and ask if the file is resolved.
6. Once all files are resolved, stage the changes: git add .
(or git add <conflicted_file>
).
7. Complete the merge commit: git commit
.
CONFIGURATION
You can configure git-mergetool behavior using git config
:
git config --global merge.tool <toolname>
: Sets your default merge tool.git config --global mergetool.<toolname>.path <path/to/tool>
: Specifies the exact path to your tool if it's not in your system's PATH.git config --global mergetool.<toolname>.cmd '<command-line-template>'
: Defines a custom command to launch the tool, using placeholders like$BASE
,$LOCAL
,$REMOTE
,$MERGED
for the respective file paths.git config --global mergetool.prompt false
: Automatically launches tools without prompting.
SEE ALSO
git-merge(1), git-diff(1), git-difftool(1), git-add(1), git-config(1)