Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WSL + Fork Tutorial #608

Open
Stanzilla opened this issue Jan 8, 2020 · 47 comments
Open

WSL + Fork Tutorial #608

Stanzilla opened this issue Jan 8, 2020 · 47 comments

Comments

@Stanzilla
Copy link

I'm probably not the only one who wants to fully rely on WSL for any development work done on Windows. Yet, I still want to keep using Fork on Windows as my Git GUI of choice. Now, there are a few obstacles here but I think the community should come together and provide a tutorial for like minded people.

There are a few open issues that prevent a "perfect" flow:

New things that might help:

Thoughts?

@DanPristupov
Copy link
Contributor

Since WSL is a virtual machine with a different file system, the majority of git operations will be very slow.

@Stanzilla
Copy link
Author

That depends, in WSL v2, when you have your project content inside of the EXT4 volume, it's actually close to native speeds. It only becomes slow when you touch files outside of it since it has to translate everything to NTFS then.

@Haprog
Copy link

Haprog commented Jan 9, 2020

I'd love to have this working better. I'm still on WSL v1 iirc (last I checked v2 was beta or something and I didn't try it yet).

I do all my command line stuff in WSL (using zsh as my default shell and runnig it in Hyper terminal. I have Hyper setup so it automatically starts wsl.exe and it opens my default shell (zsh). I have all the needed command line tools (git, build tools etc for frontend development) installed in WSL. VS Code has good integration for WSL and it can seamlessly work with projects that are either in normal NTFS partitions or in the WSL filesystem (using their official WSL "remote" plugin).

First I tried having all my git repos in WSL too but I had problems and couldn't get Fork to work (at least some git operations were failing no matter how I tried configuring Fork).

The best workaround I have found so far is to keep my git repositories under regular windows filesystem. I can still work on them in my terminal via WSL just using a path like /mnt/c/repos. But I need to have Git installed both in WSL and also in Windows and I need to duplicate my Git configuration on both sides. Now I can use Fork with the repos normally and everything seems to work fine.

But I'd like to keep the repos in WSL if Fork would work with that kind of setup.

@Haprog
Copy link

Haprog commented Jan 9, 2020

I also tried configuring "Integration / Shell / Custom" in Fork to make the "Console" button open Hyper, but I was not able to make it open Hyper terminal in the correct directory (where the selected repository is in). Not sure if the problem is with Hyper, my Hyper config or with Fork. So now I need to open my terminal manually and navigate to the correct directory instead of a convenient button to open directly from Fork.

I used to work on macOS and there it was really nice that Fork could open iTerm in the correct dir just by clicking the Console button.

@DanPristupov
Copy link
Contributor

@Haprog this is offtopic. Fork passes working directory to the selected shell application, not sure why Hyper doesn't handle it. (#504)

@Stanzilla
Copy link
Author

This is probably a good start https://github.com/carlolars/wslgit/blob/fork-patch/README.md#usage-in-fork, currently not really working well for me though. Maybe @carlolars can provide input here?

@carlolars
Copy link

Since WSL is a virtual machine with a different file system, the majority of git operations will be very slow.

I can't say that I notice any difference in speed when using the bundled git compared to using wslgit. It must be slower yes, but it's far from very slow, not noticeable during daily use for me at least. I've used other git-GUIs that were slow for real, I was really pleased when I found Fork and paired it with wslgit.
I have my repos on the Windows filesystem which is mounted inside WSL.

@Stanzilla
Copy link
Author

That will change come WLS2 though. You will want to move your files inside the container otherwise it's horribly slow. Talking 2min42s for a npm build here that inside of the container takes 15s. They do know about that limitation and are working on further improvements though. But it will launch this slow.

@carlolars
Copy link

Yes WSL2 will be slow I've heard, hopefully they will find a solution.

I tried to open a repository in the WSL filesystem using the UNC path, (\\wsl$\Ubuntu-18.04\tmp\gittest), but Forks directory browser can't handle such path. But if I add the repository manually to settings.json in AppData\Local\Fork then it works in Fork 😄

@Stanzilla
Copy link
Author

Opening from \\wsl$\Ubuntu\home\stan\projects\personal worked for me but is super slow. Not using WSLGit right now, so that's probably an issue in it?

@carlolars
Copy link

Opening from \\wsl$\Ubuntu\home\stan\projects\personal worked for me but is super slow. Not using WSLGit right now, so that's probably an issue in it?

I just did some testing on accessing the WSL1 filesystem from \\wsl$ and come to think about this thread. Yea Git for Windows is super slow when accessing the WSL filesystem:

From within WSL, repo on WSL filesystem:
performance: 0.012072600 s: git command: git status -sb -uno
From Power Shell using `wslgit`, repo on WSL filesystem accessed via \\wsl$:
performance: 0.015478500 s: git command: git status -sb -uno
From Power Shell using Git for Windows, repo on WSL filesystem accessed via \\wsl$:
performance: 7.721625300 s: git command: git.exe status -sb -uno

And the numbers for accessing a repo on Windows filesystem:

From within WSL, repo on Win filesystem:
performance: 0.064751800 s: git command: git status -sb -uno
From Power Shell using `wslgit`, repo on Win filesystem:
performance: 0.065414400 s: git command: git status -sb -uno
From Power Shell using Git for Windows, repo on Win filesystem:
performance: 0.761321800 s: git command: git.exe status -sb -uno

The repo was cloned using wslgit so that is likely why Git for Windows was slower on the Windows fs, because of some attribute-mismatch or something.

@Stanzilla
Copy link
Author

Yeah it's almost impossible to use :/

@wmertens
Copy link

wmertens commented Apr 7, 2020

I'm using Fork on the exported \wsl$ directory and the speed is ok but I needed to set core.filemode=false.
If Fork could somehow communicate with a git running inside WSL, that would be perfect.

@wmertens
Copy link

wmertens commented Apr 9, 2020

Perhaps it would be enough to use wsl git as the git executable instead of git.exe?

PS Microsoft.PowerShell.Core\FileSystem::\\wsl$\Ubuntu\home\wmertens\MyProject> wsl git status
On branch funstuff
Your branch is up to date with 'origin/funstuff'.

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

        modified:   scripts/fetch-db.sh

@carlolars
Copy link

wsl git status works fine becase wsl will start a shell in the current directory translated to the WSL filesystem and then the git status command is just executed there.
It will fail when you pass arguments that are absolute windows paths, which WSL has no idea what it is, or if you pass arguments that are relative paths separated with backslashes (Windows accepts both \ and / as separator, Linux only accepts /).
And if the git command returns a path then the Windows side will have no idea where it is. Check for example the output of wsl git rev-parse --show-toplevel when you are in a repo on \wsl$.

But, I think that it would not be that hard for the Fork-team to implement support for WSL since they have full knowledge of all the arguments they pass, and knows when to expect paths that needs translation between Win<->WSL. Its just a matter of priority.
To be honest I thinkt that it will eventually happen when more developers start to use WSL 😃

@Stanzilla
Copy link
Author

I hope so as well, a git gui client is one of the last things preventing me to really like wsl

@Stanzilla
Copy link
Author

Hey @DanPristupov any news here? Many apps, for example JetBrains, have now implemented native support for WSL Git, is this something you would want to do as well?

@DanPristupov
Copy link
Contributor

We were planning to work on it, but then decided to add Pull Requests first (#984) :p.

It's still in our todo list though.

@Stanzilla
Copy link
Author

Awesome, thanks!

@DanielSWolf
Copy link

Has there been any progress on this? I recently moved to WSL for most of my programming, and I'd really love a way to continue using Fork.

@Stanzilla
Copy link
Author

Has there been any progress on this? I recently moved to WSL for most of my programming, and I'd really love a way to continue using Fork.

The included WSL interop is still work in progress and you can find the latest build in the PR linked above. It still has a lot of problems so I would not suggest relying on it yet.

@brechtm
Copy link

brechtm commented Feb 22, 2022

I've had Fork working well with wslgit. See andy-5/wslgit#112 and other issues at the wslgit project site for some pointers.

@dougd
Copy link

dougd commented Sep 6, 2022

Any update on this? I'd love to be able to use Fork on my code hosted inside WSL2....

@greenkalx
Copy link

greenkalx commented Apr 18, 2023

I got this working with the latest executable provided on #701
this: Fork-1.82.13-WSL.zip
That's with latest 1.83.1.0 installed, but running the fork.exe from Fork-1.82.13-WSL.zip

There is an icon showing which repos are in WSL:

It's slow due to WSL2?, any suggestions for speed?

@DanPristupov
Copy link
Contributor

DanPristupov commented Apr 18, 2023

@greenkalx show report from Repository -> Performance Benchmark. You can also compare results with and without WSL build.

@greenkalx
Copy link

Attached Performance Benchmark of NTFS vs WSL2: benchmark01.txt

I have seen suggestions to switch to WSL1, or run WSL2 on ext4 filesystem.
But I'm already running git on the ext4 partition:

$ which git
/usr/bin/git
$ df -Th
Filesystem     Type      Size  Used Avail Use% Mounted on
/dev/sdb       ext4      251G   18G  221G   8% /

Microsoft suggest WSL1 for Performance across OS file systems: table of WSL versions

benchmark01.txt

@DanPristupov
Copy link
Contributor

DanPristupov commented Apr 18, 2023

WSL2
Measuring system latency
Measurements (s): 4.141*, 4.118, 4.124, 4.118, 4.119, 4.124, 4.116*
Avg: 4.121s

That's very slow. It shows that the minimum request to WSL takes longer than 4 seconds. Do you use Fork-1.82.13-WSL.zip? It usually shows a better performance.

Check Task Manager, what process uses most CPU during the benchmark? May be it's an antivirus.

I have seen suggestions to switch to WSL1, or run WSL2 on ext4 filesystem.

I think WSL1 is kind of deprecated.

@greenkalx
Copy link

greenkalx commented Apr 18, 2023

I tried again with Fork-1.82.13-WSL.zip, but same results: benchmark03.txt

In Task Manager, total CPU usage is below 5%.
There is a Vmmem process running at 0.1% CPU using 8,007.1 MB.

In WSL, there's nothing running over 0.3% (seen in 'top')

The Benchmark is giving an error sometimes:
image

benchmark03.txt

@greenkalx
Copy link

I saw there were updates in Dec 2022 for 9P, with performance improvements.

Tried updating the wsl kernel:
Linux MMM8-2 5.10.102.1-microsoft-standard-WSL2 #1 SMP Wed Mar 2 00:30:59 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
wsl --update
Linux MMM8-2 5.15.90.1-microsoft-standard-WSL2 #1 SMP Fri Jan 27 02:56:13 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux

But the speed got worse, from a score of 2.4 to 1.6.

fork_benchmark04_.txt

@greenkalx
Copy link

greenkalx commented Apr 24, 2023

I thought to reboot Windows 11 host after the wsl kernel update, and the benchmark is much better!

26.1 on WSL2 repo 1
32.2 on NTFS repo 1
42.9 on NTFS repo 2

Suddenly it becomes workable.

Still using the ForkWin-1.83.10-WSL.zip build.

fork_benchmark05.txt

@epicserve
Copy link

Installing wslgit was confusing, so I left this comment with what worked for me.

Signing commits with 1Password doesn't work, even though it works inside WSL/Ubuntu. Has anyone else gotten commit signing to work?

@chiefie
Copy link

chiefie commented Jan 2, 2025

I got commit signing working, but I don't use 1Password with GIT/SSH.

What I've used is SSH generated from within WSL2 and making that works on GIT CLI first, with check the github repo etc.

@epicserve
Copy link

Do you have something similar to this in your ~/.gitconfig inside WSL?

[user]
        name = Brent O'Connor
        email = [email protected]
        signingkey = ssh-ed25519 <redacted>
[core]
        sshCommand = ssh.exe
        excludesFile = ~/.gitignore
        autocrlf = input

[gpg]
  format = ssh

[gpg "ssh"]
  program = "/mnt/c/Users/BrentO'Connor/AppData/Local/1Password/app/8/op-ssh-sign-wsl"

[commit]
  gpgsign = true

@chiefie
Copy link

chiefie commented Jan 2, 2025

Also, I don't think you will need "wslgit.zip" anymore. Make sure to install the normal Fork.app first then download the Fork-WSL (from this thread: #701 (comment)).

@chiefie
Copy link

chiefie commented Jan 2, 2025

Do you have something similar to this in your ~/.gitconfig inside WSL?

[user]
        name = Brent O'Connor
        email = [email protected]
        signingkey = ssh-ed25519 <redacted>
[core]
        sshCommand = ssh.exe
        excludesFile = ~/.gitignore
        autocrlf = input

[gpg]
  format = ssh

[gpg "ssh"]
  program = "/mnt/c/Users/BrentO'Connor/AppData/Local/1Password/app/8/op-ssh-sign-wsl"

[commit]
  gpgsign = true

Yup. The main difference that I can think of is I don't use 1Password SSH - I do use 1Password for password management. I had tried 1Password SSH once but it really fucked up my SSH access so much that I just gone back to tried-and-true way of simple SSH.

@epicserve
Copy link

@chiefie,

Thank you for the help. I was able to get everything working by:

  1. Download Fork and installing it from https://cdn.fork.dev/win/Fork-2.2.3.exe.
  2. Then I downloaded, https://cdn.fork.dev/prerelease/Fork-2.3.20-WSL.zip
  3. I extracted all the files and then ran Fork.exe from C:\Users\BrentO'Connor\Downloads\Fork-2.3.20-WSL\Fork-2.3.20-WSL

What is the proper way to "install" Fork-WSL, so I don't have to run it from my Downloads directory?

@epicserve
Copy link

What I did to finish is:

  1. Copy the folder "\Fork-2.3.20-WSL" from C:\Users\BrentO'Connor\Downloads\Fork-2.3.20-WSL\Fork-2.3.20-WSL to C:\Program Files\Fork-2.3.20-WSL
  2. Create a shortcut by clicking the Fork.exe in C:\Program Files\Fork-2.3.20-WSL once, then hold down alt and drag a shortcut to the taskbar or wherever you want your shortcut.
  3. Optional: Create a shortcut inside WSL/Ubuntu cd /usr/local/bin && sudo ln -s /mnt/c/Program\ Files/Fork-2.3.20-WSL/Fork.exe fork. This allows you to run fork . inside a project to open it in Fork.

There are a lot of steps, and they don't provide a good user experience, so it would be nice if this could be simplified.

@chiefie
Copy link

chiefie commented Jan 13, 2025

@epicserve

This is my .gitconfig

[user]
	email = <redacted>
	name = <redacted>
	signingkey = /home/wsl/.ssh/id_rsa.pub
[gpg]
	format = ssh

As for the installation of the Fork.app, I installed the normal version on Windows 11, downloaded the WSL-forked version, extracted it a suitable location, make a shortcut of the Fork-WSL version, and that's it.

As mentioned in previous post, I don't use 1Password for SSH and just use the WSL/Debian's ssh-agent.

@trifonov-borislav
Copy link

trifonov-borislav commented Jan 15, 2025

Fork-WSL only works if the location where the repo is cloned is the default WSL distro, otherwise shows a git not found error even though 'which git' shows it's installed. For example, after I installed docker, docker made the default distro docker-desktop. I had to set it back to Ubuntu before Fork-WSL started working again. 'wsl -l --all' can be used to see which is the default distro and 'wsl -s Ubuntu' fixed the issue for me. Fork-WSL should already know which distro is being used since the path begins with \wsl$<distro>... so this should be easy to fix in the next release. (Using core.fileMode=true since in some cases filemode might be changed intentionally and I need to keep track of this)

@GRRedWings
Copy link

I have been trying to get fork to work with my WSL instance. I am using Ubuntu 24.04 and the 2.3.20-WSL instance of fork.

Fork is setup so that it is using the Fork git instance. As soon as I try to open up a git project in Fork that resides in WSL I get the following error

fatal: not a git repository (or any parent up to mount point /mnt)
Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set).

I have multiple distros of WSL, but I 24.04 is the default instance (but not installed first).

Any other ideas on what I could be doing wrong or missing would be greatly appreciated.

@epicserve
Copy link

FYI, I upgraded to the official release of v2.5.0.0 of Fork, which broke WSL Git. I had to add it again in the Fork settings.

Image

Is there anyone listening on the Fork team who can get a solution merged into Fork that doesn't require all these manual steps? This isn't very pleasant!

@DanPristupov, are you on the team?

@GRRedWings
Copy link

@epicserve what are all the manual steps you need?

Are you running the normal v2.5.0.0 of fork, or the special WSL2 build?

@chiefie
Copy link

chiefie commented Mar 12, 2025

If I recall correctly, with newer WSL2 build, you don't actually need this special wslgit anymore. At least I'm not using it anymore.

@chiefie
Copy link

chiefie commented Mar 12, 2025

Also, I don't think you will need "wslgit.zip" anymore. Make sure to install the normal Fork.app first then download the Fork-WSL (from this thread: #701 (comment)).

Case in point, I mentioned this back in Jan 2025.

@epicserve
Copy link

@GRRedWings,

@epicserve what are all the manual steps you need?

Are you running the normal v2.5.0.0 of fork, or the special WSL2 build?

Image

@epicserve
Copy link

@chiefie,

If I recall correctly, with newer WSL2 build, you don't actually need this special wslgit anymore. At least I'm not using it anymore.

I don't think this is accurate. I just tried it. I uninstalled Fork and deleted wslgit. Then I downloaded https://cdn.fork.dev/prerelease/Fork-2.3.20-WSL.zip. Also, I couldn't find anywhere that links to WSL releases, so I used this version. I would like to use a newer one but, I couldn't find one.

After installing Fork-2.3.20-WSL.zip, it doesn't show any choice for a git instance.

Image

Also, it doesn't seem like I can upgrade it. It just freezes at 0%.

Image

@chiefie
Copy link

chiefie commented Mar 13, 2025

With the Git instance, you have to manually point to the one installed from the proper version (I upgraded/installed with 2.6.1). I have/use Fork-WSL 2.3.20-WSL as well.

Image

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

No branches or pull requests