Trying to get git and Beyond Compare to place nicely together on WSL. Here is the output from git config --list
:
diff.tool=bc3
difftool.prompt=false
difftool.bc3.path=/mnt/c/Program Files/Beyond Compare 4/BComp.exe
merge.tool=bc3
mergetool.prompt=false
mergetool.bc3.trustexitcode=true
mergetool.bc3.path=/mnt/c/Program Files/Beyond Compare 4/BComp.exe
Here is my ~/.gitconfig
:
[diff]
tool = bc3
[difftool]
prompt = false
[difftool "bc3"]
path = /mnt/c/Program Files/Beyond Compare 4/BComp.exe
[merge]
tool = bc3
[mergetool]
prompt = false
[mergetool "bc3"]
trustExitCode = true
path = /mnt/c/Program Files/Beyond Compare 4/BComp.exe
my git --version is
:
git version 2.25.1
When I try git difftool file_in_git_repo
Beyond Compare opens with the current version in the left pane, but nothing in the right pane (I have confirmed the file exists in the git repo.)
.git/config
has no entries referencing diff or merge
Any suggestions would be most welcome
========================================================================
Similar to VonC's suggestion, I was able to get it working with this in my .gitconfig file (disclaimer - I have not used the mergetool with this new method):
[diff]
tool = bc3
[difftool]
prompt = false
[difftool "bc3"]
cmd = '/mnt/c/Program Files/Beyond Compare 4/BComp.exe' \"$(wslpath -aw $LOCAL)\" \"$(wslpath -aw $REMOTE)\"
[merge]
tool = bc3
[mergetool]
prompt = false
[mergetool "bc3"]
trustExitCode = true
cmd = '/mnt/c/Program Files/Beyond Compare 4/BComp.exe' \"$(wslpath -aw $LOCAL)\" \"$(wslpath -aw $REMOTE)\"
Check if this configuration might work in your case:
I managed to get it working using the built-in wslpath command which comes with new WSL versions!
My git config on WSL linux side:
difftool.bc3.cmd=BComp.exe "$(wslpath -aw $LOCAL)" "$(wslpath -aw $REMOTE)" mergetool.bc3.cmd=BComp.exe "$(wslpath -aw $LOCAL)" "$(wslpath -aw $REMOTE)" "$(wslpath -aw $BASE)" "$(wslpath -aw $MERGED)"
BComp.exe
is in my$PATH
.
I'm using WSL2 on Windows version 2004 (build 19041), and this works both inside the WSL filesystem and also for the mounted Windows filesystem.The new
wslpath -aw
converts the Linux paths like this:$ wslpath -aw /home/ \\wsl$\Debian\home
And Windows paths like this:
$ wslpath -aw /mnt/c/Users/ C:\Users
This makes them both work perfectly with the Windows version of BC when launched from Linux.
void-pointer adds in the comments:
I have some other workflows that complicate this, namely the fact that I sync my
.gitconfig
,.bashrc
, and general home directory files across multiple platforms which adds another layer of complexity.
I agree: storing WSL-specific commands directly in a single synced file can break non-WSL machines.
Instead, you can use a directory-based conditional include so that only repos under your WSL home directory pick up the extra settings.
In your main (synced) ~/.gitconfig
, add:
[includeIf "gitdir:/home/your_username/projects-wsl/"]
path = ~/.gitconfig-wsl
The [includeIf "gitdir:/home/your_username/projects-wsl/"]
line tells Git: "If the repository's path begins with /home/your_username/projects-wsl/
, load the file ~/.gitconfig-wsl
next."
Then create a local file ~/.gitconfig-wsl
(and do not sync it). In that file, put only your WSL-specific diff/merge lines:
[difftool "bc3"]
cmd = BComp.exe "$(wslpath -aw $LOCAL)" "$(wslpath -aw $REMOTE)"
[mergetool "bc3"]
cmd = BComp.exe "$(wslpath -aw $LOCAL)" "$(wslpath -aw $REMOTE)" \
"$(wslpath -aw $BASE)" "$(wslpath -aw $MERGED)"
trustExitCode = true
You main ~/.gitconfig
(synced everywhere) contains all your platform-agnostic settings.
But your local ~/.gitconfig-wsl
(WSL only, not synced) lives only on your WSL distro: Git will load it whenever you work on a repo under /home/yourusername/projects-wsl/...
(i.e. any WSL-native repo). On macOS, Linux VM, or Windows-native Git, that gitdir:
condition never matches, so Git never tries to load ~/.gitconfig-wsl
.
That way:
~/.gitconfig
remains safe and generic for any platform.~/.gitconfig-wsl
and only apply when you are actually in a WSL-based repository under /home/yourusername/projects-wsl/
.