'How to use VS Code as merge and diff tool in SourceTree?
This question and some others discuss how this could work on a Mac, but I couldn't find documentation from Microsoft or Atlassian on a way to do this on Windows without trying to make it the global Git setting. (I just prefer to change things within the IDE where possible.)
What are the parameters to use with the "Custom" settings in SourceTree's "Options" dialogue "Diff" tab, for diff'ing and merging with VS-Code?
Solution 1:[1]
I was able to set up with the following steps using the code.cmd script:
- Setting "Custom" as the external tool for both diff and merge
- Pointing to the
code.cmdcommandC:\Users\[username]\AppData\Local\Programs\Microsoft VS Code\bin\code.cmd
Using the same command-line arguments as @HeyHeyJC explains
The command-line arguments for Diff'ing are:
--diff --wait "$LOCAL" "$REMOTE"
And for Merging:
-n --wait "$MERGED"
For me I was then able to use both diff and merge from Sourcetree.
Note: By default the code.cmd file contained a command line argument to open the CLI instructions "%~dp0..\resources\app\out\cli.js", and having this open each time was a bit tedious! I removed this so my file looked as follows, and now only the files sent from Sourcetree are opened.
@echo off
setlocal
set VSCODE_DEV=
set ELECTRON_RUN_AS_NODE=1
call "%~dp0..\Code.exe" %*
endlocal
Solution 2:[2]
You need to do below configuration in Sourcetree
Go to Sourcetree ? Tools ? Options ? Diff
In the section External Diff / Merge, select Custom for the External Diff Tool and Merge Tool
Diff Arguments ?
--diff --wait "$LOCAL" "$REMOTE"Merge Arguments ?
-n --wait "$MERGED"After configuration is saved, then goto the Sourcetree and right click on the file with merge conflicts Resolve Conflicts ? Launch External Merge Tool
Note: Diff and Merge command should point to
C:\Users\<user name>\AppData\Local\Programs\Microsoft VS Code\Code.exe
Solution 3:[3]
On macOS it is sufficient to put code in the "Diff Command" box. Then use the arguments specified above by HeyHeyJC
Solution 4:[4]
You can also keep on open bouth Sourcetree and Visual Studio with opened project that you works on. And when conflict occurs switch to Visual Studio Git Changes View. Visual Studio and other tools like Sourcetree synchronize with current repository state so when you checkout to branch or make commit in other tool it displays in Visual Studio and vice versa. Same with conflicts. And when you resolve conflict in VS this will be displayed in Sourcetree. If you lazy like me, this can solve your problem without configuring anything.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Peter Mortensen |
| Solution 2 | Swapnil |
| Solution 3 | Russell Owen |
| Solution 4 |


