Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

How to Configure Visual Studio as Diff and Merge Tool for Git

DZone 's Guide to

How to Configure Visual Studio as Diff and Merge Tool for Git

Learn more about configuring Visual Studio for Git.

· Open Source Zone ·
Free Resource

After almost six years, the post on How to configure diff and merge tool in Visual Studio Git Tools is still read by people that found it useful, but it is now really really old and needs to be updated.

That post was written when Visual Studio 2012 was the latest version and the integration with Git was still really young, made with an external plugin made by Microsoft and with really basic support. If you use Visual Studio 2017 or greater, you can simply go to Team Explorer and open settings of the repository.

Figure 1: Git repository settings inside Visual Studio Team ExplorerFigure 2: Git settings inside Visual StudioFigure 3: Diff and Merge tool configuration inside Visual Studio.

Settings pane contains a specific section for Git where you can configure settings for the current repository or Global settings that are valid for all repositories of the current user.

If you open the Repository Settings, usually, you find that no specific diff and merge tool is set. Merge and Diff configurations are typical settings that are made at the user level and not for each individual repository.

As you can see, in Figure 3, no diff or merge tool was set for the current repository; this means that it will use the default one for the user (in my situation is none). If you use only Visual Studio, these settings are not so useful; if you have a conflict during merge or rebase, Visual Studio will automatically show conflicts and guide you during merging.

If you are inside Visual Studio, it will handle diff and merge automatically, even if it is not configured as Diff or Merge Tool. The rationale behind this choice is that if you are inside a tool (like VS) that has full support for diff and merge, the tool will automatically present you with diff and merge capabilities without checking repo configuration.

Figure 4: Git diff and merge section as saved from Visual Studio 2019 preview

This happens because when you open a Git Repository, Visual Studio monitors the status of the Repository and, if some operation has unresolved conflicts, it shows the situation to the user without the need to do anything. The settings in Figure 3 is useful only if you are operating with some other tool or with the command line. If you got a conflict during an operation started from any other tool (GUI or command line), the procedure is:

  1. Opening VS

  2. From VS Team Explorer, localize the local git repository and open it

  3. Go to the Team Explorer Changes pane to start resolving conflicts

If you configured instead VS as diff and tool, you can simply issue a git mergetool command and everything will be done automatically without any user intervention.

But to be honest, the latest VS git integration is really good and it is surely better to manually open the local repository. As an example, if you are doing a rebase from the command-line and you got conflicts, it is better to manually open VS, solve the conflict, and then continue to rebase the operation inside VS. If you receive further conflicts, you do not need to wait for VS to reopen it with the git mergetool command.

But if you really want to configure VS as diff and merge tool, if you press "Use Visual Studio" button ( Figure 3), you can modify your local gitconfig. The net result is similar to what I suggested in my old post, VS just adds the six sections for diff and merge in the config file.

If Visual Studio is your tool of choice, I simply suggest you configure it globally (file named %userprofile%\.gitconfig) so you can invoke the merge tool from everywhere and have Visual Studio handle everything.

Hope this helps! Let us know your thoughts in the comments below.

Topics:
open source ,git ,visual studio ,merge ,diff ,tutorial ,os ,command-line ,vs

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}