How to setup kdiff3 as a git mergetool in WSL

I have been developing in windows WSL recently and I encountered a problem, when in case of a merge conflict how to use a good GUI mergetool.

I really like the kdiff3 on windows, so here is how you can set it up as a default mergetool in Git

  1. Download and install the latest version of kdiff3 for windows fromhere http://kdiff3.sourceforge.net/
  2. Setup kdiff3 in your path, so that WSL can easily find it
    1. Click on start button and search env and open “Edit the system environment variables”

2. Then click on Enviroment Variables button

3. Then select Path and click Edit button

4. Then click New and Add the Path where KDiff3 is installed under Program Files

Setting up default merge tool in Git

Open WSL terminal and type in the following commands to set kdiff3 as the default

git config --global merge.tool kdiff3
git config --global mergetool.kdiff3.path "/mnt/c/Program Files/KDiff3/kdiff3.exe"
git config --global mergetool.kdiff3.trustExitCode false

git config --global diff.guitool kdiff3
git config --global difftool.kdiff3.path "/mnt/c/Program Files/KDiff3/kdiff3.exe"
git config --global difftool.kdiff3.trustExitCode false
git config --global difftool.kdiff3.cmd 'kdiff3.exe \"`wslpath -w $LOCAL`\" \"`wslpath -w $REMOTE`\"'

That’s it! Now if you run git mergetool command, kidff3 will open up as your default merge tool.


Posted

in

by

Tags:

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *