Could not read from remote repository make sure you have the correct access rights?

반응형

요며칠동안 깃랩에 소스를 몇번을 올렸는데

clone with ssh 주소를 이용해

깃 저장소로 커밋을 하고 푸시를 할 때 다음과 같은 에러를 많이 만났다

Could not read from remote repository.

Please make sure you have the correct access rights

and the repository exists.

처음 에러를 확인 했을 때 ssh키를 할당하지 않아서 하는 문제였다.

그런데 ssh를 설정해 주었는데도 똑같은 에러가 발생한다.

그럴 땐 ssh주소가 아닌 https 주소를 이용하여 보자.

remote를 만든 주소가 origin이라면

git remote set-url origin (해당주소) 

를 입력하여 url을 변경하여 주고 

git push -u origin --all

을 이용해 푸시해주면 된다.

깃 연동하다 머리가 터질거같다.....

저작자표시

'소프트웨어  > 그 외' 카테고리의 다른 글

[GitLab]Error : Could not read from remote repository.Please make sure you have the correct access rightsand the repository exists.  (0) 2021.10.20

Before you can read from a private repository or write to a Git repository, you must be authenticated. If you use the wrong Uniform Resource Locator (URL) to connect to a repository, or have incorrectly set up your Secure Shell (SSH) authentication, you’ll encounter the “fatal: Could not read from remote repository” error.

This guide discusses what this error means and why you may see it. It walks you through two potential solutions so you can overcome this problem when using Git.

fatal: Could not read from remote repository

SSH is a protocol for authenticating with remote devices. SSH is commonly used to authenticate with Git because you don’t need to type in your password every time you authenticate.

Every platform has its own way of authenticating users over SSH. Using GitHub, for instance, you must provide your SSH key on their dashboard. Then, you can use the SSH URL associated with your repository to authenticate with GitHub.

By default, the private SSH key for your device will be in a file called ~/.ssh/id_rsa. This file is in the hidden .ssh directory in your root folder. This key will only exist if you have generated it. Otherwise, you’ll need to use the ssh-keygen command to generate a new key.

If you have not correctly set up SSH authentication, Git will be unable to verify your identity. 

The two common causes to the “fatal: Could not read from remote repository” error are:

  • Not adding your SSH key to the SSH agent
  • Using a HTTP URL to connect to a repository

Let’s discuss each of these causes.

Cause #1: SSH Agent Issue

The SSH agent stores your SSH key. When you try to authenticate with a Git repository over SSH, Git will check the SSH agent for your key.

Your SSH key can be removed from the SSH agent for various reasons. This will make it impossible to authenticate with a Git repository.

Let’s try to clone a Git repository that is private to our local machine:

git clone :career-karma-tutorials/ck-git

When we try to sign in, the Git command line returns an error:

fatal: Could not read from remote repository.

This error informs us we have an authentication issue. If you encounter an SSH authentication issue, your first port of call is to add your key to the SSH keychain:

This will add our id_rsa key to the keychain.

Another common mistake is to add the wrong key to your keychain. If you use a key with a different name than id_rsa to authenticate with Git, make sure you add that key to your keychain and not the id_rsa key.

Could not read from remote repository make sure you have the correct access rights?

Find Your Bootcamp Match

  • Career Karma matches you with top tech bootcamps
  • Access exclusive scholarships and prep courses

Select your interest
First name

Last name

Email

Phone number

By continuing you agree to our Terms of Service and Privacy Policy, and you consent to receive offers and opportunities from Career Karma by telephone, text message, and email.

Cause #2: Using a HTTP URL

There are two ways you can authenticate with Git: over HTTP and SSH. The Hypertext Transfer Protocol (HTTP) method requires specifying your username and password to a Git server to access a repository. 

To authenticate with HTTP, you’ll use a URL that looks like this:

https://github.com/career-karma-tutorials/ck-git

You cannot use this URL to connect to a Git server over SSH. This is because SSH and HTTP are different protocols. If you try to sign in to the above URL using SSH, you’ll be prompted to enter your username and password.

We’ve got to use an SSH URL to connect to a repository over SSH. You can verify the URLs that you use to connect to a remote repository using the git remote -v command:

origin https://github.com/career-karma-tutorials/ck-git (fetch) origin https://github.com/career-karma-tutorials/ck-git (push)

We can see that our “origin” remote uses HTTP instead of SSH. For an existing repository, we can change our URL to use SSH using the git remote set-url command:

git remote set-url origin :career-karma-tutorials/ck-git

This command sets the “origin” URL to be equal to our SSH URL. Now that we’ve run this command, our existing Git repository will use the SSH URL to connect to the remote version of the repository.

If you are cloning a new repository, you don’t need to change the URL with which you are working. Instead, you just need to make sure you use an SSH URL to clone the repo:

git clone :career-karma-tutorials/ck-git

Now, we can run commands like git pull, git commit, and git push on our repository because we have the correct access privileges.

Conclusion

The Git “fatal: Could not read from remote repository” error occurs when there is an issue authenticating with a Git repository. This is common if you have incorrectly set up SSH authentication.

To solve this error, make sure your SSH key is in your keychain and you connecting to a repository using the correct URL.