obsidian-git: [Bug]: custom Git binary path using wsl doesn't work

[note: suspected cause at the very end; skip ahead and come back if that’s not it]

I have Git installed in WSL and added a shell script in my home that will take care of connecting to the ssh-agent etc. followed by actually running the requested git command. Despite the command working in both PowerShell and plain CMD, Obsidian Git reports “cannot run git command”.

  • Are you sure that the custom git binary path code actually works?
  • If yes, what’s the required format?

I have tried both C:\Windows\System32\wsl.exe /home/REDACTED/bin/ogit as well as just wsl.exe /home/REDACTED/bin/ogit or wsl /home/REDACTED/bin/ogit (in case there’s a problem with handling backslashes…)

In CMD and PowerShell, both work:

C:\Users\REDACTED\Desktop\maps\obsidian>wsl /home/REDACTED/bin/ogit status
On branch master
Your branch is ahead of 'origin/master' by 2 commits.
  (use "git push" to publish your local commits)

Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

        modified:   .obsidian/plugins/obsidian-git/data.json


C:\Users\REDACTED\Desktop\maps\obsidian>C:\Windows\System32\wsl.exe /home/REDACTED/bin/ogit status
On branch master
Your branch is ahead of 'origin/master' by 2 commits.
  (use "git push" to publish your local commits)

Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

        modified:   .obsidian/plugins/obsidian-git/data.json

C:\Users\REDACTED\Desktop\maps\obsidian>C:\Windows\System32\wsl.exe /home/REDACTED/bin/ogit push
Host key fingerprint is SHA256:<redacted>
Enumerating objects: 38, done.
Counting objects: 100% (38/38), done.
Delta compression using up to 8 threads
Compressing objects: 100% (27/27), done.
Writing objects: 100% (29/29), 6.13 KiB | 184.00 KiB/s, done.
Total 29 (delta 4), reused 0 (delta 0)
To <redacted>:repos/obsidian-vault.git
   <redacted>..<redacted>  master -> master

In Obsidian, all variants fail.

So there seems to be some special formatting / adjustment to the command required to make it work when run from Obsidian. (Or maybe it just doesn’t work at all?)


While I don’t really understand JS & related languages, from a quick scan of the code in src/simpleGit.ts, the following seem strange:

  • isGitInstalled, commitAll, and push all appear to hard-code the git command; if isGitInstalled gatekeeps the running of all other commands, then it’s not surprising that nothing works

About this issue

Most upvoted comments

Progress! After the update, I’m getting /bin/bash: status: command not found which is exactly the error message that wsl status generates.

So it looks like something drops the second part of wsl /home/REDACTED/bin/ogit, and I confirmed that with an experiment. (Details below.)

For now, I added an extra git.cmd wrapper somewhere in the %PATH% and then wondered why it doesn’t work until I found out that apparently I need to add the full C:\... path in spite of it being in %PATH% (where both cmd and powershell find & run it without problems). So now things mostly work for me!

I’d love to see the argument-dropping problem fixed eventually (so I no longer need the second wrapper) but it’s not urgent.


Experiment: To test the argument dropping, I added symlinks named status, branch, … in /usr/local/bin to another wrapper that calls /home/REDACTED/bin/ogit "$(basename "$0")" "$@" (i.e. reroutes those program names to become a git command), such that wsl status, wsl branch, … will work like wsl /home/REDACTED/bin/ogit status, … and that confirms this guess: With that in place, I can select the branch from the drop-down in the obsidian-git config and I get a “git: ready” in the status bar, i.e. basic communication with git works. (Adding lots of other wrappers for add/commit/push/… means I can use the source control view to add, commit, push/pull and it all works, as verified externally.)


Just for reference, in case others want my full solution for getting WSL’s git working: There’s a git.cmd

@echo off
C:\Windows\System32\wsl.exe /home/REDACTED/bin/obsidian-git %*

and since %PATH% search doesn’t work anyway, just place that anywhere and specify the full path to it as the custom command. On the Linux side, there’s the obsidian-git wrapper that connects to the running ssh-agent and then calls git:

#!/bin/sh
source ${HOME}/.profile > /dev/null 2>&1 # this is where my config does the ssh-agent connecting
git "$@"

and in case you don’t have an automated ssh-agent setup yet, eval "$(keychain --eval --agents ssh)" in e.g. your .profile with keychain installed gets that done without lots of duplicate ssh-agents. (Just ssh-add the key once after boot to unlock/cache it and you’re done.)

Just noticed activity on this issue - wanted to put in my 2 cents since I have a working solution that satisfies me.

My motivation: I want Windows Obsidian to use WSL’s git for obsidian-git, because my WSL has my ssh keys in the agent and also my git repo has git-crypt set up.

  1. I have the latest obsidian-git patched with #587 (just updated to latest in my fork)
  2. I have the Custom Git binary path setting point to C:\Users\<user>\AppData\Local\scripts\wsl_git.cmd I believe I didnt run into the issue described above simply because my Windows user has no spaces. I’d suggest attempting to escape them with \ , but can’t test that theory.
  3. Contents of wsl_git.cmd, inspired by this thread:
@echo off
wsl.exe /home/<wsl user>/bin/obsidian-git %*
  1. Contents of ~/bin/obsidian-git, which ensures my env is properly set up (most importantly, the correct SSH_AUTH_SOCK):
#!/bin/bash
source ${HOME}/.profile > /dev/null 2>&1
git "$@"

The last one is optional, if you don’t need your .profile you can just have wsl_git.cmd pointing to the wsl git binary instead.

With this setup, obsidian-git pulls and pushes to my remote seamlessly using my WSL auth configuration.

Hope this helps!