How to use Visual Studio Code as the default editor for Git MergeTool

Eric D. Johnson

Today I was trying to use the git mergetool on the Windows command prompt and realized that it was defaulting to use Vim, which is cool, but I'd prefer VS Code.

How can I have Visual Studio Code function as my GUI for handling merge conflicts (or even as a diffing tool) for Git?

Eric D. Johnson

As of Visual Studio Code 1.13 Better Merge was integrated into the core of Visual Studio Code.

The way to wire them together is to modify your .gitconfig and you have two options.

  1. To do this with command line entries, enter each of these: (Note: replace " with ' on Windows Git Bash, macOS and Linux as clarified by Iztok Delfin and e4rache)

    1. git config --global merge.tool vscode
    2. git config --global mergetool.vscode.cmd "code --wait $MERGED"
    3. git config --global diff.tool vscode
    4. git config --global difftool.vscode.cmd "code --wait --diff $LOCAL $REMOTE"
  2. To do this by pasting some line in the .gitconfig with Visual Studio Code.

    • Run git config --global core.editor "code --wait" from the command line.
    • From here you can enter the command git config --global -e. You will want to paste in the code in the "Extra Block" below.

      [user]
          name = EricDJohnson
          email = [email protected]
      [gui]
          recentrepo = E:/src/gitlab/App-Custom/Some-App
      # Comment: You just added this via 'git config --global core.editor "code --wait"'
      [core]
          editor = code --wait
      # Comment: Start of "Extra Block"
      # Comment: This is to unlock Visual Studio Code as your Git diff and Git merge tool
      [merge]
          tool = vscode
      [mergetool "vscode"]
          cmd = code --wait $MERGED
      [diff]
          tool = vscode
      [difftool "vscode"]
          cmd = code --wait --diff $LOCAL $REMOTE
      # Comment: End of "Extra Block"
      

Now from within your Git directory with a conflict run git mergetool and, tada, you have Visual Studio Code helping you handle the merge conflict! (Just make sure to save your file before closing Visual Studio Code.)

Accept Incoming Change anyone?

For further reading on launching code from the command line, look in this documentation.

For more information in git mergetool check out this documentation.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

How to use Visual Studio Code as Default Editor for Git

From Dev

How Do I Setup Microsoft Visual Studio: Code as a Default Editor?

From Dev

Setting Visual Studio Code as my Mac's default editor (including editing Git commits)

From Dev

Windows 10 - How do I set Visual Studio Code as my default HTML editor?

From Dev

How do I make Visual Studio Code default script editor in Unity3d?

From Dev

Extend visual studio code editor

From Dev

License for "Visual Studio Code" editor?

From Dev

Visual Studio Code editor in Terminal

From Dev

How to do git push in Visual Studio Code?

From Dev

Error mergetool code compare in git

From Java

Which font is used in Visual Studio Code Editor and how to change fonts?

From Java

How to add a right margin to the Visual Studio Code editor?

From Dev

How to google from the context menu of the Visual Studio 2015 code editor

From Dev

How to use git mergetool with Cloud9 IDE?

From Dev

How does Visual Studio choose which editor to use for a file?

From Dev

How to use Visual Studio editor to replace and keep part of a string

From Dev

Visual Studio 2013 editor default font size?

From Dev

How to use Delve debugger in Visual Studio Code

From Dev

How to use custom font in visual studio code

From Dev

How to use custom font in visual studio code

From Java

How to edit default dark theme for Visual Studio Code?

From Java

What is the Visual Studio Code editor built on

From Dev

How to use Edge as default browser with Visual Studio 2013?

From Dev

Any way to use Visual Studio Code editor instead of nano/vim/emacs to edit files?

From Dev

Any way to use Visual Studio Code editor instead of nano/vim/emacs to edit files?

From Java

How can I view the Git history in Visual Studio Code?

From Java

Visual Studio Code how to resolve merge conflicts with git?

From Dev

How to git push to a different branch with Visual Studio Code?

From Dev

How do I push a Git tag in Visual Studio Code?

Related Related

  1. 1

    How to use Visual Studio Code as Default Editor for Git

  2. 2

    How Do I Setup Microsoft Visual Studio: Code as a Default Editor?

  3. 3

    Setting Visual Studio Code as my Mac's default editor (including editing Git commits)

  4. 4

    Windows 10 - How do I set Visual Studio Code as my default HTML editor?

  5. 5

    How do I make Visual Studio Code default script editor in Unity3d?

  6. 6

    Extend visual studio code editor

  7. 7

    License for "Visual Studio Code" editor?

  8. 8

    Visual Studio Code editor in Terminal

  9. 9

    How to do git push in Visual Studio Code?

  10. 10

    Error mergetool code compare in git

  11. 11

    Which font is used in Visual Studio Code Editor and how to change fonts?

  12. 12

    How to add a right margin to the Visual Studio Code editor?

  13. 13

    How to google from the context menu of the Visual Studio 2015 code editor

  14. 14

    How to use git mergetool with Cloud9 IDE?

  15. 15

    How does Visual Studio choose which editor to use for a file?

  16. 16

    How to use Visual Studio editor to replace and keep part of a string

  17. 17

    Visual Studio 2013 editor default font size?

  18. 18

    How to use Delve debugger in Visual Studio Code

  19. 19

    How to use custom font in visual studio code

  20. 20

    How to use custom font in visual studio code

  21. 21

    How to edit default dark theme for Visual Studio Code?

  22. 22

    What is the Visual Studio Code editor built on

  23. 23

    How to use Edge as default browser with Visual Studio 2013?

  24. 24

    Any way to use Visual Studio Code editor instead of nano/vim/emacs to edit files?

  25. 25

    Any way to use Visual Studio Code editor instead of nano/vim/emacs to edit files?

  26. 26

    How can I view the Git history in Visual Studio Code?

  27. 27

    Visual Studio Code how to resolve merge conflicts with git?

  28. 28

    How to git push to a different branch with Visual Studio Code?

  29. 29

    How do I push a Git tag in Visual Studio Code?

HotTag

Archive