How to use Visual Studio as your Git mergetool
When I first started using Git, I quickly found out I needed to wire up a third party visual merge tool for handling conflicts (merging in the console was just too cool for me). I Google’d around and came back with KDiff3, SourceGear Diff Merge, Perforce P4V, and Beyond Compare. I had heard good things about Beyond Compare but it’s not free, so I ended up going with Perforce P4V.
After using P4V for a while, I saw a teaser that TFS Online was going to support Git and in that video happen to see a demo using Visual Studio to perform 3-way merges. A 3-way tool that doesn’t look like it came from 1998, is in my IDE of choice, and is easy to use… perfect! So I set out looking for how to access the 3-way merge exe that Visual Studio used and how to wire it up to work with Git. Once I got it working, I haven’t turned back. Here are the instructions.
The first thing you need to do is locate where your VS DiffMerge Tool is (NOTE: I believe this only exists for Visual Studio 2012 and 2013). It should be located within the Visual Studio installation folder, by default this should be (change 12.0 to 11.0 for VS 2012):
C:/Program Files (x86)/Microsoft Visual Studio 12.0/Common7/IDE/vsdiffmerge.exe
Next you need to find your git global config file to wire up VS as your merge tool. If you are Windows Vista or higher, this will be at C:\Users[Your Login].gitconfig (if you don’t see it, you may need to show hidden files in your folder options). Once you find the file, open it with your favorite editor (e.g., Notepad, Notepad++, Sublime Text, Visual Studio, etc.). You will need to make the following edits/additions to this file, but two things to note: 1) recommend backing up your original prior to doing so, and 2) the path to vsdiffmerge.exe will be different if you are using 2012 or installed VS in another drive/folder:
[diff]
tool = vsdiffmerge
guitool = vsdiffmerge
[difftool]
prompt = false
[difftool "vsdiffmerge"]
cmd = '"C:/Program Files (x86)/Microsoft Visual Studio 12.0/Common7/IDE/vsdiffmerge.exe"' "$LOCAL" "$REMOTE" //t
keepbackup = false
trustexistcode = true
[merge]
tool = vsdiffmergetool
[mergetool]
prompt = false
[mergetool "vsdiffmergetool"]
cmd = '"C:/Program Files (x86)/Microsoft Visual Studio 12.0/Common7/IDE/vsdiffmerge.exe"' "$REMOTE" "$LOCAL" "$BASE" "$MERGED" //m
keepbackup = false
trustexistcode = true
For further explanation of making customized changes to your git global config refer to the following http://git-scm.com/book/en/Customizing-Git-Git-Configuration
Once you have saved your edits, you should now see Visual Studio getting launched when calling git mergetool and git difftool.