URL of the remote repository that you are trying to clone is not correct.You might be cloning a private repository but your user credentials are not correct.
There are other reasons as well due which this error can occur which we will discuss later.
Below, we’ve illustrated several examples of this error alongside their respective solutions. We recommend examining each example and its solution, as they cover most scenarios in which this error occurs.
Example 1: Cloning a wrong URL of a repository:
Let’s say we are trying to clone a repo on our computer, and we mistakenly enter a wrong URL to clone. We will get this error:
To solve this error, we simply have to go to the GitHub page of the repository that we are trying to clone and click on the code button. Then in the local tab, we click on the clipboard option next to the https field. Now we can clone that repository by typing in “git clone [URL-of-repository]” and pressing Enter.
Note: Make sure the repository that you are trying to clone is not a private repository as it would need authentication in the form of a private key (as username and password authentication) has been removed from GitHub.
In our scenario, we can simply use “git clone [correct-url-of-repository]” and press enter. Afterward, we can view the contents of the cloned repository by changing the directory to the local cloned repository and executing the “ls” command inside it.
Example 2: Cloning a private repository:
If you are cloning a private repository and facing this error, it is possible that you don’t have the correct credentials for the remote repo to authenticate with and are trying to clone that repository. There are multiple solutions for this scenario.
1. Configure git correctly for authentication
You can set your username and email with the git config command. You can use this command to set your username:
To set your email, you can use this command:
Next, you need to have a valid personal access token for your GitHub account that has read access to the particular repository that you are trying to clone. If you don’t have a personal access token yet, you can create it by following these steps: After, you have copied the token and set your username and email, you can simply put in the command: Git will now ask you for your personal access token, paste the token that you have copied and press Enter. The remote repository will now be cloned on your computer. You can then cd into the directory to check whether it’s successful or not. If the above solutions didn’t fix the problem at your end, you can try these solutions listed below.
Give Read / Write Access to a Repository:
This error can also occur if you are trying to clone a repository to which your user doesn’t have read access. If you are cloning a private repository, make sure your access token has the repo permissions all ticked and then try and clone the repository. If someone else has added you to a project on GitHub, ask them to give your user read access so you can clone the repository. If you want to push changes, ensure that your user has write permissions to the repository as well.
Remove github.com Credentials from your System:
Some users have faced this problem when they had old github.com credentials on their computer while the credentials on github.com have been changed. You can delete the github.com password from the Keychain Access if you are using Mac. If you are using Windows, you can delete the credentials from the credential manager. To delete credentials from credential manager in Windows, follow these steps: To delete a keychain from the KeyChain Access App on Mac, do this: If any of the above solutions didn’t fix the problem for you you can view the GitHub docs and as well as the git documentation. As it would most likely fix the problem for you. If that doesn’t help either, you can always comment on this post and one of our technicians will help you with the problem that you are facing.















