Git:致命错误:无法从远程仓库读取

623

我想要使用http://danielmiessler.com/study/git/#website来管理我的网站,现在正尝试设置git。

按照指示,我已经完成了最后一步:git push website +master:refs/heads/master。

我在win7中使用git ming32命令行进行工作。

$ git push website +master:refs/heads/master
Bill@***.com's password:
Connection closed by 198.91.80.3
fatal: Could not read from remote repository.

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

这里可能存在一个问题,即程序正在寻找Bill@***.com。当我通过ssh连接到我的站点时,我的用户名不同(假设为“abc”)。因此,也许应该是abc@***.com。如果是这样的话,我不知道如何更改,或者是否可以使用别名推送。


2
我曾经遇到过同样的问题,有时候出现这个错误是因为git服务器无法访问或者出现了“内部服务器错误”之类的问题。 - Morteza
6
请先查看.git/config文件,确保一切都是正确的。对我来说,它的set-url和origin值是错误的。 - mixdev
在我的情况下,我不得不关闭我的WiFi并重新打开它。其他互联网服务都可以使用,包括fast.com,但由于某种原因,GitHub的操作无法正常工作。 - Joshua Pinter
这篇文章提供了很多答案。对于我同时使用工作和个人Git帐户的SSH问题,这篇文章解决了我的问题。https://www.freecodecamp.org/news/manage-multiple-github-accounts-the-ssh-way-2dadc30ccaca/ - Stephane
在我的情况下,我输入了错误的远程URL。该错误与SSH身份验证失败无法区分。 - John Jiang
显示剩余8条评论
62个回答

9

我也遇到了同样的错误。解决方法如下: 我在.git/config中更正了我的url。 只需将其从HTTPS克隆URL复制即可。可能看起来像这样:

url = https://github.com/*your*git*name*/*your*git*app*.git

它有效了。


如果我在Windows操作系统的配置文件中写了这个,错误会以不同的方式出现,它会说...“/c/Users/asus/.ssh/config: line 5: Bad configuration option: url”。 - gumuruh
使用SSH上的HTTPS很好用,它会要求输入用户名和密码。 - Kiran
@Kiran,这不好。 - Marco Castanho

9

以下是对我有效的相当简单的解决方案:

问题
$ git clone git@github.com:xxxxx/xxxx.git my-awesome-proj
Cloning into 'my-awesome-proj'...
ssh: connect to host github.com port 22: Connection timed out
fatal: Could not read from remote repository.
这也应该超时
$ ssh -T git@github.com
ssh: connect to host github.com port 22: Connection timed out
这可能有效
$ ssh -T -p 443 git@ssh.github.com
Hi xxxx! You've successfully authenticated, but GitHub does not provide shell access.
覆盖SSH设置
$ vim ~/.ssh/config

# You can also manually open the file and copy/paste the section below
# Add section below to it
Host github.com
  Hostname ssh.github.com
  Port 443
然后再试一次
$ ssh -T git@github.com
Hi xxxxx! You've successfully authenticated, but GitHub does not
provide shell access.
现在尝试克隆(应该可以工作)
$ git clone git@github.com:xxxxxx/xxxxx.git my-awesome-proj
Cloning into 'my-awesome-proj'...
remote: Enumerating objects: 15, done.
remote: Counting objects: 100% (15/15), done.
remote: Compressing objects: 100% (14/14), done.
remote: Total 15 (delta 0), reused 15 (delta 0), pack-reused 0
Receiving objects: 100% (15/15), 22.90 KiB | 4.58 MiB/s, done.

参考文献: 这里 => 使用端口443来使用HTTPS


尽管此链接可能回答了问题,但最好在这里包含答案的关键部分并提供链接作为参考。如果链接页面发生更改,则仅限链接的答案可能会失效。-【来自审查】 - aaossa
这确实帮了我。它突然停止工作,这是解决问题的方法。 - hugronaphor

7

经过一些研究,我终于找到了解决方案。您已经声明了一个环境变量来指定plink.exe路径。因此,如果您删除该路径,重新打开git bash并尝试通过SSH克隆,它将起作用。

请参考此链接

http://sourceforge.net/p/forge/site-support/2959/#204c


7
如果在执行"git push origin master"命令时,出现错误"could not read from remote repository",可以尝试以下方法:
1.ssh-keygen -t rsa -b 4096 -C "youremail"
2.eval $(ssh-agent -s)
3.ssh-add ~/.ssh/id_rsa
4.clip < ~/.ssh/id_rsa.pub(it copies the ssh key that has got generated)
5.then go to your remote repository on github and goto settings-> SSH and GPG keys ->new SSH key ->enter any title and paste the copied SSH key and save it
6. now give git push origin master 

4

我已经尝试了各种方法,包括生成新的密钥、添加到GitHub账户、编辑.ssh/config.git/config等,但仍然出现相同的错误。 然后我尝试了以下命令,它成功地解决了问题。

ssh-agent bash -c 'ssh-add ~/.ssh/id_rsa; git clone git@github.com:username/repo.git'

正如之前提到的,你尝试过运行 ssh -T git@github.com 吗?这对我有效。 - Mike S.
1
@MikeS。不,我没有尝试过那个。如果我再遇到类似的问题,我会尝试一下。谢谢。 - Chetan Pangam

4
在您的.git/config文件中:
[remote "YOUR_APP_NAME"]
    url = git@heroku.com:YOUR_APP_NAME.git
    fetch = +refs/heads/*:refs/remotes/YOUR_APP_NAME/*

并且简单地
git push YOUR_APP_NAME master:master 

4

如果您使用Gitlab,那么在尝试pull或push之前,您可能需要登录并接受Gitlab的新条款。


为什么要踩我?当天我解决了我的问题,这似乎与新的GitLab条款有关。 - Marcelo Agimóvel
请撤销您的踩。这是一个有效的答案,它发生在GitLab条款更改后。接受GitLab的新条款可能会解决问题。 - Marcelo Agimóvel

4

1
GitHub的链接不再有效。请尝试使用:https://www.githubstatus.com/。 - Rafs

4

你需要使用HTTPS访问Git:

在终端中输入以下命令:

$ git remote set-url origin abc@***.com:path/to/httpURLRepo

然后提交(commit):

$ git add .
$ git commit -m "This is the commit message"

对我来说,使用 https 而不是 ssh 可以解决问题:git clone https://gitlab.com/user/project.git - shasi kanth

4

2020年10月更新

当您有多个用户从同一客户端系统访问相同的Git服务器时,大多数情况下,Git服务器会将访问密钥与两个用户允许的用户混淆。但当您执行命令时,它会使用默认用户。

ssh -T git@gitlab.com

查看正在与你一起推送的用户,请尝试使用该用户

简单的解决方案是从Git服务器上删除未使用的用户公钥。

然后尝试进行Git fetch或pull、push操作,这将对我有效。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接