Software & AppsOperating SystemLinux

Solving Git Clone “Operation not permitted” Error in WSL Ubuntu Distro

Ubuntu 12

In your journey as a developer, you may encounter the “Operation not permitted” error when trying to clone a Git repository in Windows Subsystem for Linux (WSL) Ubuntu distro. This error can be a roadblock, but fear not, there are several solutions to this issue. This article will guide you through these solutions and help you understand the root cause of the problem.

Understanding the Issue

The “Operation not permitted” error typically occurs when you’re trying to clone a repository directly into the /mnt/c/Users/... directory, which is on the Windows NTFS partition. This partition does not support Linux permissions commands like chmod, causing this error.

Solution 1: Mount the Windows Drive with the “metadata” Option

The first solution is to mount your Windows drive with the “metadata” option. This option allows WSL to store Linux metadata on files and directories.

Open a WSL terminal and run the following commands:

sudo umount /mnt/c
sudo mount -t drvfs C: /mnt/c -o metadata

In the above commands, umount is used to unmount the specified filesystem. mount is then used to mount the filesystem. -t drvfs specifies the type of the filesystem, and -o metadata is an option to store Linux metadata.

Please note, you should replace “C:” with the drive letter you’re having the issue with.

Solution 2: Automatically Mount Windows Drives with the “metadata” Option

If you want to avoid running the above commands every time you start WSL, you can set the “metadata” option to be enabled automatically.

To do this, you need to edit the /etc/wsl.conf file. If this file doesn’t exist, create it. Add the following lines:

options = "metadata"

After you’ve made these changes, reboot Windows or restart WSL for the changes to take effect.

Solution 3: Accept the Limitations of NTFS Partitions

Another solution is to accept the limitations of NTFS partitions and work within them. Instead of trying to clone the repository directly into the /mnt/c/Users/... directory, consider using the Linux partitions within WSL (e.g., /home/USER/...) for development. You can then copy built binaries to /mnt/c/Users/... for use in the Windows native environment.

Solution 4: Clone in Default WSL Location and Use Visual Studio Code for Remote Access

The last solution is to clone the repository within the default WSL location and then use Visual Studio Code’s remote access feature to access and work with the repository in WSL. This avoids the need to use /mnt/c and may provide a smoother experience.

To do this, first, clone the repository in the default WSL location:

cd ~
git clone <repository_url>

Then, open Visual Studio Code, install the Remote – WSL extension, and use it to access your repository in WSL.


Different solutions may work for different users, and there is no one-size-fits-all solution. Experiment with the suggested solutions and choose the one that works best for your specific setup. Remember, the goal is to have a smooth and efficient development environment that suits your needs. Don’t be afraid to experiment and tweak the settings until you find what works best for you.

What is Windows Subsystem for Linux (WSL)?

Windows Subsystem for Linux (WSL) is a compatibility layer that allows running Linux binary executables natively on Windows 10 and Windows Server 2019. It provides a Linux-compatible kernel interface that enables running a Linux distribution on Windows.

How do I open a WSL terminal?

To open a WSL terminal, you can search for "WSL" in the Windows Start menu and select the desired Linux distribution. This will open a terminal window where you can run Linux commands.

What is the purpose of mounting Windows drives in WSL?

Mounting Windows drives in WSL allows you to access and work with files and directories located on your Windows partitions within the Linux environment. It enables seamless integration between the Windows and Linux file systems.

How do I edit the `/etc/wsl.conf` file?

To edit the /etc/wsl.conf file, you can use any text editor available in your Linux distribution, such as nano or vim. Open a terminal, navigate to the desired location, and use the command sudo nano /etc/wsl.conf to open the file in the nano editor. Make the necessary changes and save the file.

Can I use Git in WSL to clone repositories?

Yes, you can use Git in WSL to clone repositories. WSL provides a Linux environment where you can install Git and use it just like you would on a native Linux system. The solutions provided in this article help resolve any permission-related issues that may arise when cloning repositories in WSL.

Leave a Comment

Your email address will not be published. Required fields are marked *