Last update:

Using Visual Studio as diff/merge tool in Git and SourceTree

This article was updated for Visual Studio 2017.

Today, a short note on how to set up Visual Studio as a diif and merge tool in SourceTree and Git client. It’s not commonly known that this IDE may be used for resolving merge conflicts, but as you’ll see it’s very simple to set up.

SourceTree config

First, open up the options window and go to Diff tab.

sourcetree-options

Change both External Diff Tool and Merge Tool to Custom. In the Diff Command field enter the full path to the vsdiffmerge.exe. For VS 2015 and below you can find it in the Visual Studio installation folder, under Common7\IDE subfolder. Visual Studio 2017 has it slightly more hidden. Look under Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer.

As for the arguments fields, type in the following:

Diff tool: "$LOCAL" "$REMOTE" "Source" "Target" //t
Merge tool: "$LOCAL" "$REMOTE" "$BASE" "$MERGED" //m

Click OK, and And that’s it! Now whenever a merge conflict occurs, you’ll be able to resolve it using Visual Studio.

The only downside I found is that vsdifftool may take quite some time to start up. But if you don’t close it after diffing each file, it’ll work like a charm.

Commandline Git config

By saving these settings in SourceTree, your .gitconfig file is updated with two entries: [difftool “sourcetree”] and [mergetool “sourcetree”]. In my case it looks like the following:

You can now use these to tell the commandline Git to use these when viewing a diff or merging. It’s as simple as executing two git commands:

git config --global diff.tool sourcetree
git config --global merge.tool sourcetree

Now, git difftool and git merge commands will launch Visual Studio.

Doing so is of course perfectly possible even without SourceTree. Just add the difftool and mergetool entries to your .gitconfig file (it should be located in your home folder) and execute the two git config commands shown above.

14 comments

  1. This was just what I was looking for! Thank you

    David Lambl on 8 June 2016, 21:43 +01:00 Reply
  2. Perfect. I was wondering how to set this up explicitly in SourceTree

    panodk on 5 April 2017, 14:59 +01:00 Reply
  3. thanks for this! I’m clueless with the command line so wasn’t sure of the syntax needed for the command and paramaters (quotes, how do they work?)
    so this came in very handy.

    Jon on 25 June 2017, 22:17 +01:00 Reply
    1. I’m glad I could help.

      Michał Dudak on 26 June 2017, 8:33 +01:00 Reply
  4. Can I use it without using installing visual studio?

    Josh on 7 February 2018, 21:10 +01:00 Reply
    1. I’m not aware of a vsdiffmerge version that you can use standalone, without the full VS install. It’s most likely impossible, as it basically is a feature of VS.

      Michał Dudak on 8 February 2018, 21:38 +01:00 Reply
  5. Perfect. It is successes on windows.
    But if on Mac Pro, How can i config it.
    Thank you very mach.

    Mr Wang on 7 July 2018, 9:34 +01:00 Reply
    1. I’m not aware of any built-in diff/merge tool in VS for Mac, unfortunately.

      Michał Dudak on 20 August 2018, 19:06 +01:00 Reply
  6. Great, thank you very much (y)

    Thanh on 16 November 2018, 5:13 +01:00 Reply
  7. To save someone a bit of time – the VS2017 path may differ if you have VS 2017 Enterprise.
    My path is: C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer\vsDiffMerge.exe

    David S on 10 January 2019, 18:16 +01:00 Reply
  8. For others looking, VS2019’s location is C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer\vsdiffmerge.exe

    Andy Rich on 18 July 2019, 17:24 +01:00 Reply
  9. Great, thank you very much (y)

    Chavo Markov on 27 September 2019, 13:33 +01:00 Reply
  10. Fantastic! This still works as of today for Visual Studio 2019 (VS2019).

    Tyler on 24 March 2020, 14:28 +01:00 Reply
  11. Thanks for this! I prefer using the vs merge tool — glad to see there is an easy integration to use it alongside sourcetree for my non-vs project.

    Matt Sirko on 15 May 2020, 14:36 +01:00 Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Michał Dudak