Bootstrap FreeKB - Git (Version Control) - Resolve "fatal: Could not read from remote repository"
Git (Version Control) - Resolve "fatal: Could not read from remote repository"

Updated:   |  Git (Version Control) articles

Let's say something like this is being returned when attempting to clone a repository.

Cloning into 'example'...
Repository not found
The requested repository does not exist, or you do not have permission to access it.
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

 

For example, perhaps this is being returned when attempting to clone the "example.git" repository.

git clone ssh://git@github.com/path/to/example.git

 

As the error suggests, the most obvious issue is that the repository does not exist. If the repository is on GitHub, this is as simple as going to github.com and ensuring you are using the correct HTTPS or SSH URL.

 

This error may also occur if you are not providing a username or password when attempting to clone the repository, or if you have setup key based authentication.

By default, you will be prompted to enter your password when cloning the repository. If you want to avoid the password prompt, you can use the ssh-keygen command to create an SSH public certificate and private key.

ssh-keygen -t rsa -N '' -C $(whoami)@$(hostname) -f /home/$(whoami)/.ssh/id_rsa 2>&1 >/dev/null

 

And then use the ssh-agent and ssh-add commands to store your users private key for SSH connections.

~]# eval $(ssh-agent -s)
Agent pid 2023

~]$ ssh-add /home/$(whoami)/.ssh/id_rsa
Identity added: /home/john.doe/.ssh/id_rsa (/home/john.doe/.ssh/id_rsa)

 

Assuming your users public certificate has been appended to the authorized_keys file on the SSH server, you should be able to clone the repository over SSH without having to provide your SSH password.

git clone ssh://john.doe@server1.example.com/path/to/foo.git

 

Or like this, to connect to a repository on https://github.com/.

AVOID TROUBLE

On August 13 2021, GitHub removed support for password authentication when attempting to clone a repository over HTTPS. Follow these steps to setup SSL key based authentication.

  1. Sign into https://github.com/.
  2. Select your profile > Settings.
  3. Select SSH and GPG Keys.
  4. Select New SSH Key.
  5. Paste the content of your /home/your_username/.ssh/id_rsa.pub public certificate and select Add SSH Key.

When connecting to a repository on https://github.com/, you will always use username git. If some other username is used, the connection will fail.

git clone ssh://git@github.com/path/to/foo.git

 

By default, the git clone command will clone the repository into your present working directory.  A target directory can be specified, like this. Be aware that the target directory must not already exist, as the target directory will be created as part of the cloning.

git clone https://www.example.com/foo.git /path/to/directory

 

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter c14b59 in the box below so that we can be sure you are a human.