有人看到这个错误并知道该怎么做吗?

我正在使用终端,我在根,GitHub存储库存在,我不知道现在该做什么。

> git push -u origin master
Permission denied (publickey).
fatal: Could not read from remote repository.

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

当前回答

如果您没有访问自己的存储库,或者在克隆的存储库中进行克隆(使用一些“git submodule…”“命令):

在存储库的主目录中:

$ ls -a

1. 开放”。,你会发现这样的东西:

[submodule "XXX"]
    path = XXX
    url = git@github.com:YYY/XXX.git

将最后一行更改为您需要提取的存储库的HTTPS:

[submodule "XXX"]
    path = XXX
    https://github.com/YYY/XXX.git

保存”。“Gitmodules”,并为子模块运行命令。Git”将被更新。

2. 开放”。Git”,转到“config”文件,你会发现这样的东西:

[core]
    repositoryformatversion = 0
    filemode = true
    bare = false
    logallrefupdates = true
    ignorecase = true
    precomposeunicode = true
[remote "origin"]
    url = https://github.com/YYY/XXX.git
    fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
    remote = origin
    merge = refs/heads/master
[submodule "XXX"]
    url = git@github.com:YYY/XXX.git

将最后一行更改为您需要提取的存储库的HTTPS:

    url = https://github.com/YYY/XXX.git

因此,在本例中,主要问题只是url。任何存储库的HTTPS现在都可以在存储库页面的顶部找到。

其他回答

这发生在我身上。出于某种原因,我的出身在我没有意识到的情况下被搞砸了:

检查您的设置是否仍然正确

git remote -v

url需要像ssh://git@github.com/YourDirectory/YourProject.git; 如果没有看到git@github.com,请使用

git remote set-url origin git://github.com/YourDirectory/YourProject.git

纠正错误。或者你可以使用github应用程序在特定存储库的设置面板中检查和设置主远程存储库url。

我在ssh代理中加载了2个Github身份文件。我的个人钥匙和另一把客户项目的钥匙。

我删除了引起混乱的关键:

Ssh-add -d id_rsa_github_somekey . sh

我在远程主机上使用git pull寻找类似错误消息的解决方案时发现了这个页面:

$ git pull
Permission denied (publickey).
fatal: Could not read from remote repository.

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

我通过ssh -AY remote_hostname从本地计算机连接到远程主机。这不是OP问题的解决方案,但对其他遇到这个页面的人很有用,所以把它贴在这里。

注意,在我的例子中,git pull在我的本地机器上工作良好(也就是说,ssh密钥已经设置,并添加到GitHub帐户等)。我通过将这个添加到~/来解决我的问题。Ssh /config在我的笔记本电脑:

Host *
     ForwardAgent yes

然后我用ssh -AY remote_hostname重新连接到远程主机,git拉现在工作了。配置中的更改允许将我的ssh对从本地计算机转发到任何主机。ssh的-A选项实际上是在ssh会话中转发它。点击这里查看更多细节。

这对我很有用

有2个选项在github - HTTPS/SSH

我错误地选择了SSH,因此出现了错误-_-

切换到HTTPS,然后复制url再次尝试:)

你需要生成一个SSH密钥(如果你没有的话),并将公钥与你的Github帐户相关联。参见Github自己的文档。