Git:致命:无法从远程存储库中读取.请确保您具有正确的访问权限并且存储库存在

Nap*_*ter 20 git github

我收到此错误 -

D:\Projects\wamp\www\REPO [master]> git pull origin master
Warning: Permanently added 'github.com,192.30.252.128' (RSA) to the list of known hosts.
ERROR: Repository not found.
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
Run Code Online (Sandbox Code Playgroud)

git remote -v的输出

D:\Projects\wamp\www\REPO [master]> git remote -v
origin  git@github.com:username/repo.git (fetch)
origin  git@github.com:username/repo.git (push)
Run Code Online (Sandbox Code Playgroud)

ssh -Tv git@github.com命令的最后消息-

Hi [My Username]! You've successfully authenticated, but GitHub does not provide shell access.
Run Code Online (Sandbox Code Playgroud)

我该如何解决?

小智 36

对我来说,我收到此错误是因为我的 ssh 代理未以某种方式运行。这样做有效:

eval `ssh-agent -s`
ssh-add path_to_your_key
Run Code Online (Sandbox Code Playgroud)


Siy*_*lav 35

通过您的远程"来源"的http网址更改您的ssh网址,请使用:

> git remote set-url origin https://github.com/<user_name>/<repo_name>.git
Run Code Online (Sandbox Code Playgroud)

它会在git push上询问你的GitHub密码.

  • 顺便说一句,自 2021 年 8 月 13 日起,此解决方案将无法像 Github 一样工作,因为已弃用在所有经过身份验证的操作中使用密码 (7认同)
  • 我只是尝试过,它给了我一个错误:'致命:没有这样的遥远'起源' (3认同)
  • `origin` 是远程名称。如果您将遥控器称为 origin 以外的其他名称,则仅通过复制粘贴是行不通的。用你的远程名称替换 `origin` (2认同)

Von*_*onC 15

在讨论中问道:

确实ssh -T git@github.com输出中相同的用户名(in Hi [My Username]!),如用于您的回购协议的SSH URL的一个(git@github.com:username/repo.git)?

抱歉,它没有显示相同的名称

这意味着凭证已经改变了.

一个解决办法是至少副本%HOME%\.ssh\id_rsa.pub右边的GitHub帐户的SSH密钥部分

OP增加:

我正在私人回购.所以在git@github.com:username/repo.git,

我回答:

如果您能够克隆/推送到其用户名不是您自己的GitHub帐户的repo,那一定是因为您已将先前的公共ssh密钥添加为repo所有者的该repo的贡献者.

接下来要问同一个repo所有者将当前的公共ssh密钥添加%HOME%\.ssh\id_rsa.pub到repo贡献者列表中.
因此,请与所有者核实您(意味着您的公共ssh密钥)被声明为贡献者.


PHP*_*... 15

当您使用两个 ssh 密钥访问两个不同的 GitHub 帐户时,通常会发生这种情况。

按照以下步骤解决这个问题,它看起来太长了,但相信我不会超过 5 分钟:

步骤 1:创建两个 ssh 密钥对:

ssh-keygen -t rsa -C "your_email@youremail.com"
Run Code Online (Sandbox Code Playgroud)

第 2 步:它将在这里创建两个 ssh 密钥:

~/.ssh/id_rsa_account1
~/.ssh/id_rsa_account2
Run Code Online (Sandbox Code Playgroud)

第 3 步:现在我们需要添加这些键:

ssh-add ~/.ssh/id_rsa_account2
ssh-add ~/.ssh/id_rsa_account1
Run Code Online (Sandbox Code Playgroud)
  • 您可以使用以下命令查看添加的密钥列表: ssh-add -l
  • 您可以通过以下命令删除旧的缓存密钥: ssh-add -D

步骤 4:修改 ssh 配置

cd ~/.ssh/
touch config
Run Code Online (Sandbox Code Playgroud)

subl -a configcode confignano config

第 5 步:将此添加到配置文件:

#Github account1
Host github.com-account1
    HostName github.com
    User account1
    IdentityFile ~/.ssh/id_rsa_account1

#Github account2
Host github.com-account2
    HostName github.com
    User account2
    IdentityFile ~/.ssh/id_rsa_account2
Run Code Online (Sandbox Code Playgroud)

第 6 步:更新您的.git/config文件:

步骤 6.1:导航到 account1 的项目并更新主机:

[remote "origin"]
        url = git@github.com-account1:account1/gfs.git
Run Code Online (Sandbox Code Playgroud)

如果您在他们的 git 存储库中受到其他用户的邀请。然后你需要像这样更新主机:

[remote "origin"]
            url = git@github.com-account1:invitedByUserName/gfs.git
Run Code Online (Sandbox Code Playgroud)

步骤 6.2:导航到 account2 的项目并更新主机:

[remote "origin"]
        url = git@github.com-account2:account2/gfs.git
Run Code Online (Sandbox Code Playgroud)

第 7 步:如果需要,单独更新每个存储库的用户名和电子邮件,这不是修改步骤:

导航到 account1 项目并运行这些:

git config user.name "account1"
git config user.email "account1@domain.com" 
Run Code Online (Sandbox Code Playgroud)

导航到 account2 项目并运行这些:

git config user.name "account2"
git config user.email "acccount2@doamin.com" 
Run Code Online (Sandbox Code Playgroud)

  • 这是修复同一主机(gitlab 或 github)中多个帐户的多个 ssh 密钥错误的最佳且迄今为止完美的答案 (2认同)

Tud*_*dor 8

ssh-add -D  # Delete all identities.
ssh-add ~/.ssh/your_key
Run Code Online (Sandbox Code Playgroud)

编辑 1
由于我得到了这么多选票,我发现了这种方法的一些问题,那就是它会删除您的所有身份,因此当您尝试从其他存储库读取数据时,您可能会遇到相同的问题,并且您需要再次执行此步骤对于每个项目......但也可能不是您的项目的情况


Muh*_*lim 7

这个错误也发生在我身上,因为原始存储库创建者离开了公司,这意味着他们的帐户从 github 团队中删除。

git remote set-url origin https://github.com/<user_name>/<repo_name>.git

然后 git pull origin develop或者你想执行的任何 git 命令都应该提示你登录并继续正常运行。

  • 就我而言,我与某人共享了我的 &lt;user_name&gt; - 他们必须在 git 路径上设置*他们的* &lt;user_name&gt; 才能 **push** 工作,**pull** 之前可以工作,因为我有他们的 SSH只读 SSH 密钥部分。把自己搞糊涂了,但这终于成功了!:D (2认同)

kip*_*ip2 5

有时这会发生在我身上,因为网络问题。我不完全理解问题,但切换到不同的子网或使用 VPN 解决了​​它


Jai*_*udo 5

有时,仅将pub ssh密钥复制到github / bitbucket还是不够的,尤其是对于Bitbucket。您可能还需要检查ssh是否使用了您期望的身份,而不是搞乱了git remote

检查代理程序是否使用与您粘贴在github / bitbucket上的相同身份ssh-add -l。如果缺少添加

ssh-add ~/.ssh/id_rsa_my_git_identity

更多详细信息:https : //confluence.atlassian.com/bitbucket/configure-multiple-ssh-identities-for-gitbash-mac-osx-linux-271943168.html


BSB*_*BSB 5

此错误可能是因为本地计算机上没有 SSH 密钥。在本地检查 SSH 密钥:

$ cat ~/.ssh/id_rsa.pub
Run Code Online (Sandbox Code Playgroud)

如果上面的命令没有给出任何输出,请使用下面的命令来创建 ssh 密钥(Linux/Mac):

$ ssh-keygen 
Run Code Online (Sandbox Code Playgroud)

现在再次运行cat ~/.ssh/id_rsa.pub这是您的 SSH 密钥。将此密钥复制并添加到 git 中的 SSH 密钥中。在 gitlab/bitbucket 中转到

profile settings -> SSH Keys -> add Key
Run Code Online (Sandbox Code Playgroud)

并添加密钥