Wsl linux не выполняется git clone

Обновлено: 04.07.2024

Git is the most commonly used version control system. With Git, you can track changes you make to files, so you have a record of what has been done, and have the ability to revert to earlier versions of the files if needed. Git also makes collaboration easier, allowing changes by multiple people to all be merged into one source.

Git can be installed on Windows AND on WSL

An important consideration: when you enable WSL and install a Linux distribution, you are installing a new file system, separated from the Windows NTFS C:\ drive on your machine. In Linux, drives are not given letters. They are given mount points. The root of your file system / is the mount point of your root partition, or folder, in the case of WSL. Not everything under / is the same drive. For example, on my laptop, I've installed two version of Ubuntu (20.04 and 18.04), as well as Debian. If I open those distributions, select the home directory with the command cd

, and then enter the command explorer.exe . , Windows File Explorer will open and show me the directory path for that distribution.

Linux distro Windows Path to access home folder
Ubuntu 20.04 \\wsl$\Ubuntu-20.04\home\username
Ubuntu 18.04 \\wsl$\Ubuntu-18.04\home\username
Debian \\wsl$\Debian\home\username
Windows PowerShell C:\Users\username

If you are seeking to access the Windows file directory from your WSL distribution command line, instead of C:\Users\username , the directory would be accessed using /mnt/c/Users/username , because the Linux distribution views your Windows file system as a mounted drive.

You will need to install Git on each file system that you intend to use it with.

Installing Git

Git comes already installed with most of the Windows Subsystem for Linux distributions, however, you may want to update to the latest version. You also will need to set up your git config file.

To install Git, see the Git Download for Linux site. Each Linux distribution has their own package manager and install command.

For the latest stable Git version in Ubuntu/Debian, enter the command:

You also may want to install Git for Windows if you haven't already.

Git config file setup

To set up your Git config file, open a command line for the distribution you're working in and set your name with this command (replacing "Your Name" with your preferred username):

If you don't yet have a GitHub account, you can sign-up for one on GitHub. If you've never worked with Git before, GitHub Guides can help you get started. If you need to edit your Git config, you can do so with a built-in text editor like nano: nano

Git Credential Manager setup

Git Credential Manager (GCM) Core enables you to authenticate a remote Git server, even if you have a complex authentication pattern like two-factor authentication, Azure Active Directory, or using SSH remote URLs that require an SSH key password for every Git push. GCM Core integrates into the authentication flow for services like GitHub and, once you're authenticated to your hosting provider, requests a new authentication token. It then stores the token securely in the Windows Credential Manager. After the first time, you can use Git to talk to your hosting provider without needing to re-authenticate. It will just access the token in the Windows Credential Manager.

To set up GCM Core for use with a WSL distribution, open your distribution and enter this command:

If you intend to work with Azure Repos, some additional configuration is required:

Now any git operation you perform within your WSL distribution will use GCM Core. If you already have credentials cached for a host, it will access them from the credential manager. If not, you'll receive a dialog response requesting your credentials, even if you're in a Linux console.

If you are using a GPG key for code signing security, you may need to associate your GPG key with your GitHub email.

Adding a Git Ignore file

We recommend adding a .gitignore file to your projects. GitHub offers a collection of useful .gitignore templates with recommended .gitignore file setups organized according to your use-case. For example, here is GitHub's default gitignore template for a Node.js project.

If you choose to create a new repo using the GitHub website, there are check boxes available to initialize your repo with a README file, .gitignore file set up for your specific project type, and options to add a license if you need one.

Git and VS Code

Visual Studio Code comes with built-in support for Git, including a source control tab that will show your changes and handle a variety of git commands for you. Learn more about VS Code's Git support.

Git line endings

If you are working with the same repository folder between Windows, WSL, or a container, be sure to set up consistent line endings.

Since Windows and Linux use different default line endings, Git may report a large number of modified files that have no differences aside from their line endings. To prevent this from happening, you can disable line ending conversion using a .gitattributes file or globally on the Windows side. See this VS Code doc about resolving Git line ending issues.

sudo apt update , or git clone XXX can't connect.
sudo apt update :

I checked ipconfig on PowerShell, and my vEthernet adapter for WSL isn't disconnected, and I can confirm that, as ping 8.8.8.8 actually works.

The text was updated successfully, but these errors were encountered:

TheoForay commented Sep 28, 2020

I would really like to follow the procedure to give more intel but unfortunately I don't have the Feedback Hub on my computer. I don't find a way to install it.
Perhaps it's because it's on my company's laptop.
Is there another I can provide you what you need?

ttelfer commented Oct 2, 2020

Having the exact same problem.

maxlieblich commented Oct 3, 2020

zhangshengsheng commented Oct 10, 2020

ad-on-is commented Oct 27, 2020

For me, even ping stopped working

patrickhoebeke commented Oct 28, 2020

I had exactly the same issue (Windows 10 version 1903 (build 18362.1139) + Ubuntu 18.04 though WSL2) . It turns out that my wifi was configured in Windows as "public" network. Switching to "private" fixed the problem.
Hope this can help

shiv-sid commented Oct 31, 2020

I had exactly the same issue (Windows 10 version 1903 (build 18362.1139) + Ubuntu 18.04 though WSL2) . It turns out that my wifi was configured in Windows as "public" network. Switching to "private" fixed the problem.
Hope this can help
Excellent @patrickhoebeke . This worked for me.

robpomeroy commented Nov 9, 2020

Subscribing. Initially ping to Ubuntu mirrors worked, but apt update didn't (timeout). Then finally ping stopped working too (destination unreachable).

WSL rendered unusable. Pity. Back to Hyper-V VMs (with a custom NAT vSwitch to overcome spurious WiFi adapter issues). >sigh<

Update: downgrading to WSL 1 seems to be the best option for now, while the WSL 2 bugs are ironed out?
wsl --list --verbose

wsl --set-version [distro name] 1

Thadir commented Nov 10, 2020

I did a downgrade installed stuff I needed upgraded back. But yeah WSL 2 seems to be broken for now.

trallnag commented Nov 15, 2020

Same for me. For now I'm going back into my "normal" VM :/

mickael-h commented Nov 22, 2020

Same problem for me. I had to downgrade back to WSL 1.

jacobbaek commented Nov 24, 2020

Same problem for me. Is there any workaround except downgrading back to WSL 1?

ad-on-is commented Nov 24, 2020

Guys, check your firewall-settings. For me, Bitdefender Firewall blocks WSL2 traffic.

jacobbaek commented Nov 25, 2020

@ad-on-is Thanks, I checked the firewall that i used at the desktop, this caused from firewall liked you mentioned.
I thought it is strange why ICMP is working despite other all traffics are not working. but when i disabled the firewall policy, it is working and also checked the deny log in firewall log.
Thanks again.

osmanatam commented Nov 25, 2020

i am living the same problem. in wsl1 update is working , in wsl22 update problem. any solution.

@osmanatam add two rules to your firewall that all through the network interface used by WSL2, it is worth a try.

adam-grant-hendry commented Nov 25, 2020

Same problem for me

jacobbaek commented Nov 30, 2020

Guys, check to firewall.
WSL1 and WSL2 have different network interfaces.
WSL1's network interfaces is that shared with host network, on the other hands WSL2 network interfaces has only one network intetface that works as NAT.
So WSL1 can access where the host can access. But WSL2 can not access where the host can access.

EDIT: This just fixed it temporary. The issue is back. Apparently when the network configuration changes (VPN off and then on again) then WSL2 cannot find its way to the internet anymore.

hallownfs commented Dec 13, 2020

lukee1234 commented Dec 14, 2020

robpomeroy commented Jan 5, 2021

Me also. So WSL 2 causes packet fragmentation?

exowanderer commented Feb 2, 2021

Update: downgrading to WSL 1 seems to be the best option for now, while the WSL 2 bugs are ironed out?
wsl --list --verbose

wsl --set-version [distro name] 1

I tried and tried and tried to configure my firewalls to let the WSL2 work it's magic. I followed several tutorials that all led to the same

5 ways to config the firewalls.

In the end, I set WSL version back to 1; and it worked as though 'nothing was wrong'.

Important: these steps work from Wsl1. They don't work on wsl2. So something seems to have changed here for the worse.

Specifically: I've been unable to clone from github using wsl2. I've completely wiped my windows machine and the issue still reproes. Here are the steps i've taken:

  1. I've put in a fresh install of Windows.
  2. I've upgraded to the latest insider 'fast' ring.
  3. I've installed the Ubuntu app from the store.
  4. I've enabled the following features:

I then upgraded to wsl2 using:

Logging into Ubuntu, i did the following to update/upgrade Ubuntu:

I then created an ssh key like so:

I then uploaded this key to my github account.

I then tried to clone like so:

I've been completely unable to get cloning to work.

Please use the following bug reporting template to help produce issues which are actionable and reproducible, including all command-line steps necessary to induce the failure condition. Please fill out all the fields! Issues with missing or incomplete issue templates will be closed.

If you have a feature request, please post to the UserVoice.

If this is a console issue (a problem with layout, rendering, colors, etc.), please post to the console issue tracker.

Important: Do not open GitHub issues for Windows crashes (BSODs) or security issues. Please direct all Windows crashes and security issues to secure@microsoft.com. Ideally, please configure your machine to capture minidumps, repro the issue, and send the minidump from "C:\Windows\minidump".

Please fill out the below information:

  • Your Windows build number: (Type ver at a Windows Command Prompt)

Microsoft Windows [Version 10.0.18922.1000]

  • What you're doing and what's happening: (Copy&paste the full set of specific command-line steps necessary to reproduce the behavior, and their output. Include screen shots if that helps demonstrate the problem.)

Trying to clone a github repo produces:

  • What's wrong / what should be happening instead:

Cloning should actually succeed.

  • Strace of the failing command, if applicable: (If some_command is failing, then run strace -o some_command.strace -f some_command some_args , and link the contents of some_command.strace in a gist here).

Any help would be very appreciated.

The text was updated successfully, but these errors were encountered:

CyrusNajmabadi commented Jul 1, 2019

CyrusNajmabadi commented Jul 1, 2019

Note: this is a wsl2 issue. If i convert back to wsl1 then things work:

So there is something going wrong with wsl2 here.

So what's the variable.

There are plenty of hits on your GnuTLS recv error but I'm not loving the answers (and lack thereof) being given. None of them are going to help answer how you are stuck out of a clean install.

Confirm: There wasn't a "installed my usual VPN / AV / proxy / etc" software somewhere inbetween steps 1/2/3/4 at the top. [Take as given "no" but it needs asking.]

One thing you can try while I sleep on it is install the Ubuntu-18.04 (contrast Ubuntu) version from the store. First thing out of the gate after you convert WSL2:

We can cross the ssh bridge (which has more paths to failure) later. Fact I'm drawing a total blank on how the apt upgrade would take but not the git clone . If the apt upgrade failed at least we could point finger "networking problems".

So there is something going wrong with wsl2 here.

Indeed. But that it is working for you on WSL1 unfortunately isn't hinting at the external variable that is causing a simple git clone to fail for you on WSL2.

I am running Ubuntu 18.04, as a Subsystem for Windows. I have done this in mutliple PCs and never had this problem. I try to to git clone <repo> , and I get this:

I tried the following:

❯ git config core.fileMode false , with this result fatal: not in a git directory

❯ git config --global core.filemode false

❯ git config --add --global core.filemode false

Nothing seems to work. I already tried a couple of answers here, but WSL seems a little bit more tricky. Anyone have any idea about how to solve this?

803 1 1 gold badge 5 5 silver badges 9 9 bronze badges

4 Answers 4

I had the same issue. Try this:

Change the drive letter to whatever one you're having the issue with.

10.2k 7 7 gold badges 43 43 silver badges 70 70 bronze badges 1,181 2 2 gold badges 3 3 silver badges 2 2 bronze badges The command was successful but this did not change the issue for me. I still see "operation not permitted" as git tries to chmod .git/config.lock. Worked for me. Is there some reason MS is not doing this when they mount windows locations automatically? confirmed this fixed the issue for me - had to change directory from windows file system to ubuntu to get the unmount command to work, but after running the commands, i was able to git clone my repo without permissions issue

You can automatically mount your Windows drives under WSL with the metadata option that allows apps, like git, to use chmod and fix this issue.

Edit /etc/wsl.conf (create it if it doesn't exist). Add the following:

  • Reboot Windows
  • Exit any WSL sessions, run wsl --shutdown from PowerShell or CMD, and start WSL again
  • Exit your only session, terminate it with wsl --terminate <distroName> , and start it again,

Then never worry about it again.

1,721 1 1 gold badge 2 2 silver badges 24 24 bronze badges


Thanks! This worked for me in combination with re-mounting the drive.

/mnt/c/Users/. is on the Windows NTFS partition itself, and not within the WSL's ext4 formatted system. Therefore you have to treat it as you would an NTFS partition on a USB stick on an actual Ubuntu installation, and accept the limitations of NTFS.

NTFS partitions do not support chmod or similar Linux permissions commands, and unlike in actual Ubuntu instalations which don't error but don't make any permissions changes, WSL doesn't relay this information back to you, it simply errors out as you see here.

You cannot do a git clone sanely into the /mnt/c/. space within WSL because of the Linux permission schemas and chmod not working right. This is a limitation of WSL in its current form.

Читайте также: