我有一个非常奇怪的问题与git和github。当我试着推的时候,我得到:

git push -u origin master
ERROR: Repository not found.
fatal: The remote end hung up unexpectedly

我添加了遥控器:

git remote add origin git@github.com:account-name/repo-name.git

什么好主意吗?


当前回答

我的一个Github库也有同样的问题。

方法:

使用SSH而不是HTTPS,然后推/拉开始工作正常。

其他回答

我的解决办法是:

git remote rm origin
git remote add origin https://USERNAME@github.com/username/reponame.git

类似于Emi-C的答案,但没有密码。

如果你使用https从github克隆,但你使用ssh推送,你也会得到这个错误。

要纠正这个问题,打开.git/config并替换:

Url = https://github.com/company/project.git

With

Url = git@github.com:company/project.git

你应该可以在没有任何警告的情况下推…

remote:未找到存储库。可能是一个令人沮丧的误导错误消息从github试图推到HTTPS远程,你没有写权限。

检查您对存储库的写权限!

尝试SSH远程到相同的存储库显示不同的响应:

% git remote add ssh git@github.com:our-organisation/some-repository.git

% git fetch ssh
From github.com:our-organisation/some-repository
* [new branch]        MO_Adding_ECS_configs             -> ssh/MO_Adding_ECS_configs
* [new branch]        update_gems                       -> ssh/update_gems

% git push ssh     
ERROR: Repository not found.
fatal: Could not read from remote repository.

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

“正确的访问权限?”

那你为什么不早说?

此时值得注意的是,虽然SSH失败模式在此场景中 稍微好一点,我使用HTTPS远程超过SSH,因为 GitHub推荐HTTPS over SSH。

我知道GitHub使用“未找到”的意思是“禁止”在一些 环境防止不经意间泄露了一个私人的存在 存储库。

需要身份验证的请求将返回404 Not Found,而不是 在某些地方是禁止的。这是为了防止意外泄漏 未授权用户的私有存储库。

——GitHub

这在网络上是一种相当普遍的做法,实际上它是这样定义的:

404(未找到)状态代码表示未找到原始服务器 目标资源的当前表示形式或不愿意 揭露它的存在。

——6.5.4。404未找到,RFC 7231 HTTP/1.1语义和内容(重点挖掘)

对我来说毫无意义的是,当我使用一个GitHub认证 凭据助手 并且我可以访问该存储库(已经成功地克隆和获取 它),GitHub会选择隐藏它的存在对我因为失踪 写权限。

通过网络查看https://github.com/our-organisation/some-repository/ 浏览器确认我没有写存储库的权限。我们的 团队的GitHub管理员能够在短时间内授予我的团队写访问权 好不容易,我终于把树枝推了上去。

我试了所有的办法,但似乎都不管用。进一步的研究表明:

这里有一个解决问题的综合方法。 当你数到5。修复4,注意VS代码会要求认证。

如果您输入了密码,仍然得到身份验证错误,请执行以下操作。

转到你的GitHub菜单做设置->开发人员设置->个人访问令牌->生成新的令牌。并确保这些框都是按照下图选中的。生成一个访问令牌并将其保存在可访问的地方。 使用生成的令牌而不是密码。 然后继续执行步骤6。修复5

这些步骤可以在事后解决问题。

这是如何解决我的问题

#check current github account
ssh -T git@github.com

#ensure the correct ssh key used with github
ssh-agent -s
ssh-add ~/.ssh/YOUR-GITHUB-KEY

#re-add the origin
git remote add origin git@github.com:YOUR-USER/YOUR-REPO.GIT
git push -u origin master