0

I'm migrating my dev environment to Windows subsystem for Linux WSL2 on Windows 10. I want to use TortoiseGit GUI on the win10 side for files in WSL2. How do I do that?

TaiwanGrapefruitTea
  • 1,045
  • 2
  • 14
  • 25

2 Answers2

0

What you need inorder to make TortoiseGit work on your WSL2 directory is to load a .ppk file converted from your .ssh identity being used by your WSL2 user (i.e. registered in your Gitlab/GitHub SSH Keys Settings and added on the ssh-add -l). And add it to Pageant Key List.

Here are the steps I took starting from the very beginning where I had a mistake on the WSL version I used. You can skip the steps under #1 if you don't need it.

  1. I realized that I was using WSL1 and "Ubuntu" kernel (no version number on the name from the Store). So I fix this issue first to switch to WSL2.

    1.1. I followed the Microsoft article, Manual installation steps for older versions of WSL and skipped the first 3 steps (i.e. enabling the required Windows features) because I've already done it via Control Panel > Turn Windows features on or off.

    1.2. I downloaded and installed WSL2 Linux kernel update package for x64 machines

    1.3 On Powershell, I run wsl --set-default-version 2 (Expected Output: The operation completed successfully.)

    1.4 I went back to Microsoft Store, installed Ubuntu-22.04 (i.e. latest version attow.), and Launched it's terminal.

    1.5 I run explorer.exe . to open a Windows File Explorer on that root directory of my Ubuntu. Then pinned it on Quick access so I can easily navigate on it with GUI.

  2. Check the list of SSH keys available with the following commands:

    eval `ssh-agent -s`
    
    ssh-add -l
    

    Output

    The agent has no identities.
    
  3. Run ssh-keygen and follow through the steps. I recommend to use the default output ~/.ssh/id_rsa so you don't have to manually add the custom ssh keys with the ssh-add command. Passphrase is also optional and I left mine blank so I don't have to input password on every git command execution.

  4. Go ahead and register your SSH key to your GitLab/GitHub. Make sure you copy the PUBLIC key and not the private one. For the default setup, it's from the file named id_rsa.pub.

    For GitHub, Settings > SSH and GPG keys

    For GitLab, Preferences > SSH Keys

  5. Mark your directory path as safe in the global gitconfig. There are two ways to do this:

    5.1 via your Ubuntu Terminal:

    git config --global --add safe.directory '%(prefix)///wsl$/Ubuntu-22.04/home/<username>/<path>/<to>/<repo>'
    

    5.2 via TortoiseGit GUI:

    Go to TortoiseGit Settings, Settings > Git > "Edit global .gitconfig" and add your whitelist there. Example:

    [safe]
    directory = %(prefix)///wsl.localhost/Ubuntu-22.04/home/User1/code
    

    Or you can just go ahead and use git config --global --add safe.directory '*' to disable the check entirely.

  6. Generate .ppk out of your .ssh file.

    6.1 Open TortoiseGit's PuTTY Key Generator (Example path: C:\Program Files\TortoiseGit\bin\puttgen.exe)

    6.2 Click Load and find the private key (Path to default SSH setup: \\wsl.localhost\Ubuntu-22.04\home\<username>\.ssh\id_rsa

    6.3 Click Save private key and I recommend to save the file on the same location with your ssh.

  7. Add your .ppk to the Pageant Key List.

    7.1 Open pageant.exe from the same bin folder and then double click it from the system tray (lower right corner of your taskbar) to open its window. 7.2 Click Add Key and select your .ppk file.

  8. In my case, I didn't need to restart my computer so go ahead and try using TortoiseGit immediately. The tool should work by then but you will notice that the folders don't get the icons in the file explorer. You have to add the path to your root on TortoiseGit Settings > Icon Overlays > Include paths:. In my case, I saved \\wsl.localhost\

Alex Pappas
  • 2,377
  • 3
  • 24
  • 48
-1

To get git functionality working, use this:

execute this git command:

git config --global --add safe.directory '*'

git submodule update failed with 'fatal: detected dubious ownership in repository at'

.

To get icons working, use this:

In TortoiseGit:

Settings -> Icon Overlays and enable Network drives (or add \wsl$\ as an Include path).

https://gitlab.com/tortoisegit/tortoisegit/-/issues/3694#note_497747568

TaiwanGrapefruitTea
  • 1,045
  • 2
  • 14
  • 25
  • add safe.directory '*' didn't work for me in Windows 11. – Ian Grainger Mar 08 '23 at 06:59
  • The git safe directory mechanism was added to remedy security issues. Adding `*` as a safe directory completely circumvents this security mechanism and is a _bad_ idea. Consider adding a specific folder instead, like the other answer mentions – mnme Jun 29 '23 at 06:45