How to setup git’s difftool on Windows

In this little recipe, we’re going to teach git on Windows how to run our own custom diff tool when we execute git difftool. The diff tool I’m using is WinMerge.

We’ll need to enter a few new configuration options on the command line:

git config --global diff.tool winmerge
git config --global difftool.winmerge.cmd "C:/git-difftool.bat \"$LOCAL\" \"$REMOTE\""
git config --global difftool.prompt false

Then create your wrapper script at C:/git-difftool.bat. Git will call this script when executing git difftool. That script should look like:

"C:/Program Files (x86)/WinMerge/WinMergeU.exe" -e -ub "$1" "$2"

Yes, this is using bash syntax in Windows shell! It works thanks to git, so you can execute git difftool from either the git shell or from Windows shell.

NOTE: backslashes won’t work in regular widows shell, but WILL in git shell — I know, weird! 🙂

There you are! Now you can enjoy git on Windows (ok, just kidding) AND on Linux!

6 comments on “How to setup git’s difftool on Windows

  1. still not working for me…!! it opens the WinMerge for sure.. but the files aren’t automatically added for comparison. Here is the .gitconfig file ..!!

    [diff]
    tool = winmerge
    [difftool “winmerge”]
    cmd = C:/git-difftool.bat “” “”
    [difftool]
    prompt = false

    • Here’s mine… looks like you’re missing the cmd arguments $LOCAL AND $REMOTE? Also, I put my script in E:, but that shouldn’t matter…

      [diff]
      tool = winmerge
      [difftool “winmerge”]
      cmd = e:/git-difftool.bat “$LOCAL” “$REMOTE”
      [difftool]
      prompt = false

  2. Hi Jason
    I am using GitHub and GitShell and tried to use Winmerge as difftool by making the changes in the .gitconfig and creating the .bat file, but it just does not work.
    Can you please help?
    Ira

Leave a Reply