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!

  • Guest

    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

    • http://cuppster.com Jason

      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

      • Guest

        Cool.. its running now..!! Thanks

  • Hro

    The problem is that with your blog layout, you can’t see anything past “$L

    • http://cuppster.com Jason

      I can see it OK in Chrome right now… what browser are you using? Maybe something wrong with the WP plugin I’m using…(?)