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.
- Find your Visual Studio installation. For me it was C:\Program Files (x86)\Microsoft Visual Studio 12.0
- In SourceTree, go to Tools > Options > Diff
- 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.
- 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.
Targetare just labels Visual Studio will use for the files . The
//tflag will open the diff in a temporary tab instead of a persisted tab.
- For Merge Tool set Arguments to
"$LOCAL" "$REMOTE" "$BASE" "$MERGED" //m. The
//mflag denotes it is a merge in contrast to diff.
- By default, when merging, Git will create backup files, so after merge you will be left with
.origfiles which you need to manually delete. To disable it open a command line and enter
git config --global mergetool.keepBackup false
- 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.
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.