HOWTO · Git
How to Set Up SourceGear DiffMerge Tool for Git
In this article, we will discuss the process of configuring Git to use SourceGear's DiffMerge as the default difftool.
On this page
Configure Git to open SourceGear’s DiffMerge for graphical comparisons with git difftool and merge resolutions with git mergetool. DiffMerge supports three-way comparison, so a merge view can show both sides, their common base, and the result file. Install DiffMerge first, then configure the executable path that exists on your system.
Why use DiffMerge with Git
Git can compare revisions and prepare merge inputs without a graphical application. DiffMerge presents those files together, which can make changes and conflicts easier to inspect. The comparison and merge commands use different inputs: a diff compares two versions, while a merge can include a common ancestor and a destination for the resolved file.
Configure DiffMerge on Windows
In Git Bash, configure the tool names and commands with the following copyable settings. The example assumes the typical install path shown; change it if sgdm.exe is elsewhere. The outer single quotes preserve the inner double quotes and Git placeholders in the stored command, including paths with spaces.
git config --global diff.tool diffmerge
git config --global merge.tool diffmerge
git config --global difftool.diffmerge.cmd '"C:/Program Files/SourceGear/Common/DiffMerge/sgdm.exe" "$LOCAL" "$REMOTE"'
git config --global mergetool.diffmerge.cmd '"C:/Program Files/SourceGear/Common/DiffMerge/sgdm.exe" --merge --result="$MERGED" "$LOCAL" "$BASE" "$REMOTE"'
These commands update your global .gitconfig; omit --global when you want to set a value in the current repository instead. If you prefer to edit .gitconfig directly, the two command values are "C:/Program Files/SourceGear/Common/DiffMerge/sgdm.exe" "$LOCAL" "$REMOTE" and "C:/Program Files/SourceGear/Common/DiffMerge/sgdm.exe" --merge --result="$MERGED" "$LOCAL" "$BASE" "$REMOTE".
The DiffMerge command-line reference documents the --merge mode and --result option. The merge command used in each platform example follows that syntax, passing the result path first and then the local, base, and remote files.
Configure DiffMerge on macOS
Check the executable location with command -v diffmerge. The commands below use /usr/local/bin/diffmerge, the path in the supplied example; replace it in both command values with the path reported on your Mac if it differs. The single-quoted values keep the embedded quotes and Git placeholders intact in .gitconfig.
git config --global diff.tool diffmerge
git config --global merge.tool diffmerge
git config --global difftool.diffmerge.cmd '"/usr/local/bin/diffmerge" --nosplash "$LOCAL" "$REMOTE"'
git config --global mergetool.diffmerge.cmd '"/usr/local/bin/diffmerge" --merge --result="$MERGED" "$LOCAL" "$BASE" "$REMOTE"'
Configure DiffMerge on Ubuntu
Check the executable location with command -v diffmerge. The commands below use /usr/bin/diffmerge, the path in the supplied example; replace it in both command values if your installation reports another path. The single-quoted values keep the embedded quotes and Git placeholders intact in .gitconfig.
git config --global diff.tool diffmerge
git config --global merge.tool diffmerge
git config --global difftool.diffmerge.cmd '"/usr/bin/diffmerge" --nosplash "$LOCAL" "$REMOTE"'
git config --global mergetool.diffmerge.cmd '"/usr/bin/diffmerge" --merge --result="$MERGED" "$LOCAL" "$BASE" "$REMOTE"'
Set mergetool.keepBackup to false only if you do not want Git to retain its backup copy; keeping backups can help while you are getting comfortable with the workflow.
Run Git difftool and mergetool
After configuring the tool, run git difftool to open comparisons for changed files. To compare a specific pair of revisions or a single file, supply revisions and a path, for example git difftool main feature -- src/app.py. During a merge conflict, run git mergetool or limit it to a path with git mergetool -- src/app.py. These commands need the relevant revisions or an active merge conflict; configuration alone does not create a comparison.
Run this self-contained example to write a temporary Git config and read the selected tool:
config_file="$(mktemp)"
trap 'rm -f "$config_file"' EXIT
git config --file "$config_file" diff.tool diffmerge
git config --file "$config_file" --get diff.tool
Understand the configuration and file arguments
Inspect the effective setting with git config --global --get diff.tool or open the global file with git config --global -e. The configuration names select DiffMerge as Git’s tool, and the *.cmd values tell Git how to launch it. Check that the configured executable path is valid and that quotes surround paths that can contain spaces.
Git supplies $LOCAL and $REMOTE as the two sides of the current comparison or merge operation. Their meaning depends on that operation and the revisions involved, so they are not universally the original and modified files. For a merge, $BASE identifies the common ancestor input and $MERGED identifies the file where the resolved result belongs. The merge command must pass all four paths in the order expected by DiffMerge. Keep these placeholders in the stored command; do not replace them with literal filenames. With the tool path, command names, and argument order configured for your platform, git difftool and git mergetool can launch DiffMerge for their respective tasks.