Command Reference

git-mergetool Tutorial

Explains how to use git-mergetool to launch an external merge tool for conflict resolution.

Who This Is For
  • Developers who already know basic commit and branch actions
  • Readers who want to understand command boundaries and risk
Prerequisites
  • A basic mental model of worktree, index, and commits
  • Comfort reading `git status` and a small commit graph
Common Risks
  • Using local cleanup commands on already shared history
  • Continuing to rewrite before confirming a recovery path

The short version

git-mergetool is used to launch an external merge tool for conflict resolution.

When it is a good fit

  • when you need to launch an external merge tool for conflict resolution
  • when you want this step to be repeatable instead of ad hoc
  • when you need a clearer mental model of what Git is recording or updating

Basic example

git mergetool

What to watch most closely

Advanced commands are not always part of the daily path, but mistakes with them usually cost more to recover from.

A safer working habit

Rehearse the flow on a small reproducible history before running it in a production repository.

Useful angles for understanding it

  • Handle more complex collaboration or history-analysis tasks
  • Turn one-off steps into repeatable routines
  • Reduce the risk of advanced operations

Related reading

Read it alongside git status, git log, and git show so it is easier to see how the command changes history, refs, the index, or the working tree.

What problem this command solves in a workflow

git mergetool is a conflict-resolution assistant that launches an external merge tool (vimdiff, meld, kdiff3, Beyond Compare, etc.) to help you resolve merge conflicts. It does not automatically fix conflicts — it presents the conflicting files with three views (base, local, remote) in a visual interface, making it easier to combine changes correctly than editing conflict markers by hand. After you save the resolved file in the tool, git mergetool stages the result.

Typical use cases

  • Resolving merge conflicts during git merge, git rebase, or git cherry-pick when multiple files have overlapping changes.
  • Using a visual diff tool to understand complex three-way merges where conflict markers alone are hard to reason about.
  • Standardizing conflict resolution across a team by configuring a shared mergetool (e.g., git config merge.tool meld).
  • Working through a rebase with many conflicts one file at a time, with the tool handling the staging automatically.

Diagram view

Mergetool conflict resolutionMergetool launches an external program with three file versions (base, local, remote). You resolve conflicts in the tool's interface, and the result is staged automatically.
Inputs
Conflict markers in working treeBase versionLocal versionRemote version
Results
Resolved files stagedUnresolved files remainExternal tool UI
Mergetool assists resolution — it does not auto-resolve. You must review and save the correct result in the external tool.

Special cases and boundaries

  • The external tool must be installed and configured. Run git mergetool --tool-help to see available options, then set merge.tool in your config.
  • Backup files (.orig) may be left behind after resolution. Use mergetool.keepBackup = false to suppress them if you don't need them.
  • Mergetool only handles files with active conflict markers. Clean files (already resolved or conflict-free) are skipped.
  • After all conflicts are resolved, you must still complete the operation — run git commit (for merge) or git rebase --continue (for rebase).
  • Mergetool modifies the working tree and index as you save resolved files. Unlike the read-only tools above, it does change repository state — but only within the scope of the ongoing merge/rebase operation.
  • If the external tool crashes or you close it without saving, the conflict markers remain and you can re-run mergetool.