failed-to-clone-the-repository-please-check-your-internet-connection

I recently installed GitHub for Windows for the first time so I could compile an open source project. While trying to clone the repository, I got this error:

failed to clone the repository ‘whatever
Please check your internet connection.

I knew my internet connection was working. A web search revealed answers that didn’t apply or didn’t work for me (an issue that was resolved in an earlier version, and an issue that was fixed by re-installing).

Other descriptions of the problem seemed to happen right at the beginning of the clone operation, or somewhere in the middle. For me it happened at the very end, every time.

Also, if I tried to clone the repo again after the failed attempt, it would take a long time comparing all the files, and then tell me there were thousands of uncommitted files.

So I told GutHub for Windows to stop tracking the repo, and then manually deleted the folder before my many re-attempts.

Using Git Shell

GitHub for Windows configures a Git Shell for you, which seems to be a pre-configured version of an existing shell. For me, it defaulted to PowerShell (other options were Cmd, Git Bash, and Custom). The following steps should work with any shell.

I figured I’d try to clone the repo using the command line. To do this, find Git Shell on the start menu and open it. It should start in your default storage directory (more on this later).

First, get the clone URL. This will be on the right side of the GitHub repo’s web page, like so:

GitHub HTTPS Clone URL

The command to clone a repo from GitHub is:

git clone https://github.com/project/project.git

Note: do this in the directory that will be the parent of your project. Git will create the project directory for you.

In the following screen shot, you’ll see my failed attempt. My default storage  directory is C:\Users\Briantist\Documents\GitHub (the default that GitHub for Windows chose).

Git Shell Clone Repo

I got errors that it was unable to create a few files:

error: unable to create file very/long/path/name (no such file or directory)

As well as:

fatal: unable to checkout working tree
warning: Clone succeeded, but checkout failed

Default Storage Directory and Path Name Length

You might be seeing the problem already. That very long path name is not too big by itself, but when added to the default data directory it seems to be exceeding what Windows can handle.

I simply changed the default storage directory in GitHub for Windows to C:\GitHub to keep it nice and short. This is in under tools > Options. After that I had no issues.

I suspect that this problem will affect .NET projects more than most because of the long names used in some of the files.

It was just my luck that the first repo I tried to clone contained such long file names. I hope this post helps someone else save the hour+ it took me to figure it out.