Sub topic 9
Fixing common clone errors
This chapter assumes you can run git clone over HTTPS and SSH and know the difference between the two. It also assumes you have a GitHub account. Most clone failures fall into three groups: the URL is wrong, authentication fails, or the local destination is a problem. Read the first line of the error and match it to a group.
Read the error first
Git prints the cause on the fatal: or remote: line. Start there and don't guess.
| Message | Likely cause | Fix |
|---|---|---|
| `fatal: repository '...' not found` | Typo in the URL, or a private repository you cannot see | Check owner and name. Confirm you have access. |
| `Authentication failed` | Wrong or expired credentials over HTTPS | Use a personal access token or a credential manager. |
| `Permission denied (publickey)` | SSH key missing, not loaded, or not added to GitHub | Test the key and add it. |
| `Could not resolve host: github.com` | No network, DNS failure, or proxy | Check connectivity and proxy settings. |
| `destination path '...' already exists and is not an empty directory` | The target folder already has files | Pick another name or an empty folder. |
| `Host key verification failed` | The saved GitHub host key does not match | Verify the key, then update `known_hosts`. |
Repository not found
GitHub reports a private repository you cannot access as "not found", not "forbidden". This hides whether the repository exists. So this error can mean three things: you mistyped the URL, you lack access, or you are signed in as the wrong account. Copy the URL from the green Code button instead of typing it. If the repository belongs to an organization, ask an owner to grant you access.
Authentication failed over HTTPS
GitHub removed password authentication for Git operations. When Git asks for a password, enter a personal access token instead. A credential manager, such as the one bundled with Git for Windows or macOS Keychain, can store the token. An old cached credential is a common cause. If a previously working clone now fails, remove the stale entry from your credential manager and try again.
You can also skip tokens by signing in with the GitHub CLI:
gh auth login
gh repo clone octocat/Hello-WorldPermission denied (publickey)
This error means GitHub did not accept any key your machine offered. Work through these checks in order:
ssh -T [email protected]
ssh-add -l
ssh-add ~/.ssh/id_ed25519The first command tests authentication. A working setup replies with a greeting that includes your username. The second lists keys loaded in your agent. The third loads a key if the list is empty. Adjust the filename to match your key. If the key is loaded and the test still fails, confirm the matching public key appears under your GitHub account's SSH settings.
Destination already exists
Git refuses to clone into a folder that already has contents. Either name a new directory or remove the old one if you no longer need it:
git clone https://github.com/octocat/Hello-World.git my-projectLarge clones that stop midway
Errors like RPC failed or early EOF usually point to an unstable connection or a very large history. A shallow clone downloads far less data, so it often succeeds where a full clone does not:
git clone --depth 1 https://github.com/octocat/Hello-World.gitExercise
You run git clone [email protected]:OWNER/REPO.git and get Permission denied (publickey). The same repository clones fine over HTTPS. Which command do you run first, and what does it tell you?
Show answer
Run ssh -T [email protected]. It tests whether GitHub accepts your SSH key. If it fails, run ssh-add -l to see whether a key is loaded, then load or register the key. HTTPS working shows the repository and your access are fine, so the problem is the SSH key setup.