Skip to content

execute git in WSL for WSL paths - #532

Closed
schummar wants to merge 4 commits into
desktop:mainfrom
schummar:feature/wslGit
Closed

schummar wants to merge 4 commits into
desktop:mainfrom
schummar:feature/wslGit

Conversation

@schummar

@schummar schummar commented Mar 21, 2023 •

Copy link
Copy Markdown

Motivation

Executing git commands from Windows on WSL (Windows Subsystem for Linux) paths has some problems. The major ones (that I'm aware of) are

  • The performance is bad because cross file system file access is slooow
  • By default just checking out a branch will create changes from the WSL point of view because file endings are "wrong". I know line ending behavior can be configured, but out-of-the box this creates chaos.
  • Git hooks don't work

My use case is, I would like to use GitHub Desktop to manage my git repos both in windows and in WSL, where I do most of my programming. Commonly recommended solutions like running GitHub Desktop in WSL (WSL GUIs are not stable enough for my tastes) or just opening the WSL path in GitHub Desktop on Windows (suffers from the above mentioned issues) are not working for me.

There are a number of issues that are related to this, e.g. desktop/desktop#13953

Solution

So my suggestion is this: When working in repositories that have a WSL path (e.g. \\wsl$\home\user\src\whatever or \\wsl.localhost\\Ubuntu\home\user\src\whatever), execute git commands within WSL: wsl.exe -e git .... This PR is a POC and probably needs more work, so I am grateful for any feedback. It works very smoothly in my locally built GitHub Desktop though.

My considerations so far:

Performance

The approach works a lot faster on my machine. I can't say I have done bullet proof benchmarking yet, but some of my tests show significant improvements:

Opening a repository - old:

Executing getBranches: git for-each-ref --format=%00%(refname)%00%(refname:short)%00%(upstream:short)%00%(objectname)%00%(author)%00%(symref)%00 refs/heads refs/remotes (took 1.495s)
Executing getCommits: git log HEAD --date=raw --max-count=100 -z --format=%H%x00%h%x00%s%x00%b%x00%an <%ae> %ad%x00%cn <%ce> %cd%x00%P%x00%(trailers:unfold,only)%x00%D --no-show-signature --no-color --not --remotes -- (took 2.632s)
Executing getAllTags: git show-ref --tags -d (took 1.890s)

Opening a repository - new:

Executing getBranches: git for-each-ref --format=%00%(refname)%00%(refname:short)%00%(upstream:short)%00%(objectname)%00%(author)%00%(symref)%00 refs/heads refs/remotes (took 0.155s)
Executing getCommits: git log HEAD --date=raw --max-count=100 -z --format=%H%x00%h%x00%s%x00%b%x00%an <%ae> %ad%x00%cn <%ce> %cd%x00%P%x00%(trailers:unfold,only)%x00%D --no-show-signature --no-color --not --remotes -- (took 0.203s)
Executing getAllTags: git show-ref --tags -d (took 0.140s)

Checking out a branch - old:

Executing checkoutBranch: git -c credential.helper= checkout --progress master --recurse-submodules -- (took 1.679s)
[Timing] Action 'checkout branch from list' for 'schummar/schummar-state' took 3.284s

Checking out a branch - new:

Executing checkoutBranch: git -c credential.helper= checkout --progress master --recurse-submodules -- (took 0.133s)
[Timing] Action 'checkout branch from list' for 'schummar/schummar-state' took 1.094s

Authentication

WSL has a neat mechanism to forward environment variables between WSL and Windows processes. It even can convert paths while doing it. By forwarding certain env vars, authentication seem to work nicely for private repositories.

Multiple WSL distributions

Since the distribution name is part of the WLS repo path, it can be specified in the command, so working across multiple distributions should work, though I didn't test that case yet.

@refringe

Copy link
Copy Markdown

@schummar Thank you for looking into this. I would love for this feature to get merged.

@SynthLuvr

Copy link
Copy Markdown

Thanks for putting this together. I tried to get this working with my local GitHub Desktop but was unsuccessful. The error I'm seeing is "Git could not be found at the expected path"

@schummar

Copy link
Copy Markdown
Author

You need to use the modified GitHub Desktop version from this PR: desktop/desktop#16378

@schummar

schummar commented Apr 26, 2023 •

Copy link
Copy Markdown
Author

A little script for anyone who wants to try it out:

git clone https://github.com/schummar/dugite.git
git clone https://github.com/schummar/desktop.git

cd dugite
git checkout origin/feature/wslGit
yarn
yarn build
yarn link

cd ../desktop
git checkout origin/feature/wslCompatibility
yarn
cd app
yarn link dugite
cd ..
yarn build:prod

@SynthLuvr

Copy link
Copy Markdown

Thanks @schummar, that helps a lot. I'm still getting errors when running GitHub Desktop though:

  • error launching git: The system cannot find the path specified.
  • Failed to execute getStatus: ENOENT
  • Git returned an unexpected exit code '1' which should be handled by the caller (getStatus).'

It also fails to load any repository from WSL, keeps show "Can't find [repo]"

@schummar

schummar commented Apr 26, 2023 •

Copy link
Copy Markdown
Author

Ah my bad. I forgot that you have to link dugite in the app folder as well. I have updated the script.

Edit: Actually, only in the app folder. Root was just plain wrong 😬

@SynthLuvr

Copy link
Copy Markdown

It's working for me, thanks!

@CaseyLabs

Copy link
Copy Markdown

Bumping this PR! WSL-based git would be fantastic.

@SynthLuvr

Copy link
Copy Markdown

I've been running this since April. I'm too afraid to update to the latest version in case I can't get this feature working again. So I'm sticking with this PR and forgoing updates.

@schummar

Copy link
Copy Markdown
Author

I've updated the branches once again. You can create a current build if you want. 😉

@Stanzilla

Copy link
Copy Markdown

@sergiou87 any chance this can be looked at? cheers

@zainudinmuji4-commits zainudinmuji4-commits left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.github/workflows/spelling2.yml

@schummar

Copy link
Copy Markdown
Author

Closing this as there doesn't seem to be any interest from the maintainers and there are alternatives.

@schummar schummar closed this Apr 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants