Data report"State of code review 2024" is now liveRead the full report

git difftool

Greg Foster
Greg Foster
Graphite software engineer


Note

This guide explains this concept in vanilla Git. For Graphite documentation, see our CLI docs.


Git provides several tools to compare and track changes between commits, branches, and more. While git diff is commonly used for viewing differences in the command line, git difftool allows developers to use external graphical tools to view these differences more visually. This guide explains how to configure and use git difftool effectively, enhancing your workflow by leveraging visual differences.

git difftool is a frontend to git diff that allows you to use software like Beyond Compare, Meld, WinMerge, and more, to view and edit differences between commits, branches, files, and more. This can be particularly useful for visually parsing diff outputs, which might be less clear in a standard terminal.

To begin using a graphical diff viewer, you first need to configure it. Git allows configuration at the global or project level, depending on your needs.

  1. Choose a diff tool: First, ensure that you have a graphical diff tool installed on your system. Common choices include Beyond Compare, Meld, WinMerge.

  2. Configure Git to use the tool: Use the git config command to set your preferred tool. For example, to set Meld as your difftool, you can configure Git globally like this:

    Terminal
    git config --global diff.tool meld

    This sets Meld as the default tool for all your repositories. If you want to configure the difftool for just one project, navigate to your project directory and run the same command without --global.

  3. Set up tool-specific configurations: Some tools might require additional configuration parameters, such as path settings or options. For example:

    Terminal
    git config --global difftool.meld.path "/path/to/meld"
    git config --global difftool.meld.cmd "meld \"$LOCAL\" \"$REMOTE\""

    These configurations define the path to the tool and customize the command that Git uses to launch the tool.

Once you've configured your difftool, you can start using it to view differences:

Terminal
git difftool

This command will open the difftool for all changed files. You can also specify files or commits:

Terminal
git difftool HEAD~1 HEAD
git difftool branch1..branch2

These commands compare changes between two commits or branches.

  • View staged changes: To view differences between the staging area and your last commit, use:

    Terminal
    git difftool --staged
  • Launch without prompting: By default, git difftool might prompt you to launch the external tool for each file. To launch the tool once for all differences, you can use:

    Terminal
    git difftool --no-prompt
  • Learn the basics of your graphical diff tool: Understanding the features of your chosen diff tool can significantly improve how you analyze differences.
  • Regularly update your tool and Git configurations: Keeping your tools and configurations up to date ensures compatibility and security.
  • Use git diff and git difftool together: While git difftool is great for visual comparison, git diff can be quicker for small changes or when working without a GUI.

Using an external tool to view differences provides a clear and interactive way to manage code changes. It can help in understanding complex changes, resolving merge conflicts visually, and improving overall code review processes.

By integrating git difftool into your Git workflow, you can leverage the power of graphical diff viewers to enhance your efficiency and accuracy in handling code differences. This setup not only streamlines the development process but also aids in maintaining high code quality through better diff analysis.

Stay unblocked. Ship faster.
Experience the new developer workflow - create, review, and merge code continuously. Get started with one command.
Learn more

Give your PR workflow
an upgrade today

Stack easier | Ship smaller | Review quicker

Or install our CLI.
Product Screenshot 1
Product Screenshot 2