Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WSL: Using A WSL symlink folder from Windows

I use WSL almost exclusively, and only switch to main windows for browsing and running Windows native programs. I have a git repository located at /mnt/c/myrepo. In order to "install" the code inside /mnt/c/myrepo I need to move it to /mnt/c/otherlocation/renamed. Instead of executing cp -r /mnt/c/myrepo /mnt/c/otherlocation/renamed every time I do a git pull from /mnt/c/myrepo, I would like to symlink /mnt/c/myrepo to /mnt/c/otherlocation/renamed. However when I do this, the program which consumes /mnt/c/otherlocation/renamed isn't able to view the "contents" of renamed as a directory.

I have been all over the WSL github repo and issue tracker trying to find a solution to this issue. I see a lot of exclamations about how symlinks "just work". I have enabled every Windows 10 developer feature I can find, I even followed some reddit thread where someone claimed that purchasing Pengwin and creating a symlink from Pengwin would ensure this compatibility, but I still can't seem to make this work.

The basic usage I need, is allow me to view "renamed" as a directory from windows, or for windows to recognize the symlink as a symlinked directory.

from wsl:

ln -s /mnt/c/myrepo  /mnt/c/otherlocation/renamed

from windows:

  1. open file explorer
  2. navigate to c:\otherlocation
  3. open mydir and view the contents as if it were a native directory

How do I do this?

like image 858
Nathan Avatar asked Aug 20 '19 19:08

Nathan


People also ask

How do I open Windows folder in WSL?

From VS Code Start VS Code. Press F1, select WSL: New WSL Window for the default distro or WSL: New WSL Window using Distro for a specific distro. Use the File menu to open your folder.

Do Linux symbolic links work on Windows?

Symbolic links are supported by POSIX and by most Unix-like operating systems, such as FreeBSD, Linux, and macOS. Limited support also exists in Windows 7 and Windows Vista, and to some degree in Windows 2000 and Windows XP in the form of shortcut files.

Can WSL access Windows files?

WSL also allows you to run Linux command-line tools and apps alongside your Windows command-line, desktop and store apps, and to access your Windows files from within Linux. This enables you to use Windows apps and Linux command-line tools on the same set of files if you wish.


1 Answers

Do the symlink in Windows, in cmd.exe:

mklink /d C:\otherlocation\renamed C:\myrepo

It doesn't make sense creating the symlinks in WSL if both directories are in Windows.

This symlink will work in WSL as well.

like image 105
Carlos Rafael Ramirez Avatar answered Oct 26 '22 00:10

Carlos Rafael Ramirez