Resolving SourceTree Merge Conflicts with Visual Studio

I’m currently working with a company where Git is the source control repository of choice and SourceTree is the tool to handle the interactions with the repository.

Until now I’ve been a Team Foundation Server guy, and before that a Subversion guy, and before that a Visual Source Safe guy so I’ve always (with the exception of Source Safe) enjoyed working with those repositories via Visual Studio.  Personally I really like the merge Window in Visual Studio.  I know it and I’m comfortable with it so I like to use it.

Now, as you’ll know if you’re a SourceTree user, Visual Studio isn’t listed as an out of the box companion of SourceTree which disappointed me, and I just didn’t like the OpenSource options that were available to me so I Googled and I found a fantastic Visual Studio integration post here: http://www.thatdepends.net/how-to-use-visual-studio-merge-tool-with-sourcetree/.  His post is specifically for Visual Studio 2012 but for later versions all you need to do is update the path to the vsDiffMerge.exe application.

I’m republishing the instructions from Krzysztof’s post here with his blessing.  Hopefully you’ll find his help as useful as I did.

  1. Find your Visual Studio installation.  For me it was C:\Program Files (x86)\Microsoft Visual Studio 12.0
  2. In SourceTree, go to Tools > Options > DiffSourceTree options window showing Diff tab
  3. Set External Diff Tool and Merge Tool to Custom and set Diff Command in both to C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\vsDiffMerge.exe. Obviously use path to your VS installation.
  4. For External Diff Tool set Arguments to "$LOCAL" "$REMOTE" "Source" "Target" //t. Variables, prefixed with $, are specifying file paths. Note they are enclosed in quote marks, so that spaces in file paths won’t break the command. Source and Target are just labels Visual Studio will use for the files . The //t flag will open the diff in a temporary tab instead of a persisted tab.
  5. For Merge Tool set Arguments to "$LOCAL" "$REMOTE" "$BASE" "$MERGED" //m. The //m flag denotes it is a merge in contrast to diff.
  6. By default, when merging, Git will create backup files, so after merge you will be left with .orig files which you need to manually delete. To disable it open a command line and enter git config --global mergetool.keepBackup false
  7. To resolve a conflict, right click on a conflicted file in SourceTree, Resolve Conflicts > Launch External Merge Tool, resolve conflicts in Visual Studio and finish by clicking Accept Merge.

sourcetree_conflict-1435901880344

accept_merge-1435901865918

That’s all there is to it.  Now if you, like me, like Visual Studio’s merge tool then you’re literally 5 minutes away from linking it to SourceTree.