How to git clone in wsl? How to git clone in wsl? git git

How to git clone in wsl?


You don't want to use sudo here, and in general there's no reason to need it with Git unless the repository you're working with is owned specifically by root.

The problem you're seeing is that you're using a Linux Git, which expects standard Unix permissions to work, on a file system (NTFS) that does not support them. Git will try to set the permissions appropriately when it rewrites the lock file which it will rename into places as the config file, but it can't do so, and it fails. Git for Windows doesn't have this problem because it maps these permissions differently from WSL, which just always returns an error.

You can try a couple of things:

  • Just clone the repository under WSL and not under a Windows drive. This is guaranteed to work, and should be fine.
  • Clone the repository somewhere under WSL and move it into a Windows drive, either setting the config options manually for Windows or trying git init again in the repository after cloning.
  • Run git init on the Windows drive and then do a git remote add origin YOUR-REMOTE and a git pull origin master (or whatever your branch is called).

It's possible that the last one may not work any better than what you have now, since git init may fail the same way.


You can fix this by following this guide. Summary below.

From a WSL prompt:

sudo vim /etc/wsl.conf

Add these lines:

[automount]options = "metadata"

Save the file, shutdown wsl from a PowerShell prompt:

wsl --shutdown

Re-open a wsl terminal. You should see files owned by your user now instead of root. You can now git clone, chmod, chown etc.