Meld
Git
difftool
mergetool
version control

Setting up and using Meld as your Git difftool and mergetool

Master System Design with Codemia

Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.

Introduction

Meld is a graphical diff and merge tool that pairs well with Git when command-line diff output is too dense or when merge conflicts need side-by-side inspection. Git does not care which GUI tool you use, as long as you tell it how to launch that tool for diff and merge operations.

The setup has two parts: install Meld so it is runnable from the shell, then configure Git to invoke it as difftool and mergetool.

Basic Git Configuration

If meld is already on your PATH, the simplest global configuration is:

bash
1git config --global diff.tool meld
2git config --global merge.tool meld
3git config --global mergetool.meld.trustExitCode true
4git config --global difftool.prompt false

This tells Git:

  • use Meld when git difftool is called
  • use Meld when git mergetool is called
  • trust Meld's exit code during merges
  • skip the per-file confirmation prompt for diffs

You can confirm the values with:

bash
git config --global --get diff.tool
git config --global --get merge.tool

When Meld Is Not on PATH

On some systems, especially Windows or custom Linux installs, Git cannot find the meld executable automatically. In that case, define the command explicitly.

bash
1git config --global difftool.meld.cmd 'meld "$LOCAL" "$REMOTE"'
2git config --global mergetool.meld.cmd 'meld "$LOCAL" "$MERGED" "$REMOTE" --output "$MERGED"'
3git config --global merge.tool meld
4git config --global diff.tool meld

Git substitutes those environment variables when it launches the tool:

  • 'LOCAL is your version'
  • 'REMOTE is the other version'
  • 'BASE is the common ancestor during merges'
  • 'MERGED is the file Git expects you to save'

The exact pane layout may vary by Meld version, but those paths are the core integration points.

Using Meld for Diffs

After configuration, use:

bash
git difftool

or for a specific file:

bash
git difftool -- path/to/file

This is especially useful when reviewing unstaged or staged changes:

bash
git difftool --staged

Because git diff and git difftool look at the same underlying Git objects, you can switch between text and GUI review without changing your workflow.

Using Meld for Merge Conflicts

When a merge or rebase stops on conflicts, launch:

bash
git mergetool

Git opens Meld for each conflicted file. You resolve the conflicts in the GUI, save the merged result, and then continue the Git operation. A typical sequence is:

bash
1git merge feature-branch
2git mergetool
3git add .
4git commit

For a rebase, the last step would usually be git rebase --continue.

A Useful .gitconfig Block

If you prefer editing config files directly, the equivalent block often looks like this:

ini
1[diff]
2    tool = meld
3[difftool]
4    prompt = false
5[merge]
6    tool = meld
7[mergetool "meld"]
8    trustExitCode = true

That is functionally the same as the earlier git config --global commands.

Local Versus Global Configuration

If you only want Meld for one repository, omit --global and run the same configuration inside that repository. That stores the values in .git/config instead of your home directory, which is useful when different projects prefer different tools.

Why trustExitCode Matters

trustExitCode tells Git whether it should rely on the merge tool's process result to determine success. With Meld, setting it to true is common because it reduces extra prompts and keeps the workflow smoother. If your environment behaves strangely, you can turn it off and let Git ask whether the merge was completed.

Common Pitfalls

The most common problem is that Git says the tool is unknown or cannot be launched. That usually means the meld executable is not on PATH, or the configured command is wrong for the local platform.

Another issue is expecting git diff itself to open the GUI. It will not. The GUI integration happens through git difftool.

Merge users also sometimes forget that saving the file in Meld is only part of the process. Git still needs the resolved file staged with git add before the merge or rebase can finish.

Finally, be careful with blanket git add . after conflict resolution if unrelated files are present. It is often safer to stage only the files you actually resolved.

Summary

  • Configure Meld as both Git difftool and mergetool through global Git settings.
  • Use git difftool for graphical change review and git mergetool for conflict resolution.
  • If meld is not on PATH, set explicit difftool.meld.cmd and mergetool.meld.cmd values.
  • Save the resolved file in Meld, then stage it in Git.
  • 'trustExitCode usually makes the merge workflow smoother when Meld is configured correctly.'

Course illustration
Course illustration

All Rights Reserved.