首页 > 解决方案 > 为什么我刚克隆 GitHub 时会说“找不到存储库”?

问题描述

尝试对 GitHub 私有托管的 Git 存储库进行简单更改。我克隆了存储库,进行了更改,然后将其推送以供审核。git push没有成功,我想也许我在克隆存储库时对远程 URL 进行了粗暴的处理(但这不可能正确的,因为我已经成功克隆了存储库,对吧?)。我尝试删除并重新添加遥控器,但推送仍然失败:

为了说明问题:

% git remote -v               
origin    https://github.com/our-organisation/some-repository.git (fetch)
origin    https://github.com/our-organisation/some-repository.git (push)

% git fetch -v origin
From https://github.com/our-organisation/some-repository
= [up to date]        MO_Adding_ECS_configs             -> origin/MO_Adding_ECS_configs
= [up to date]        update_gems                       -> origin/update_gems

% git push -v origin
Pushing to https://github.com/our-organisation/some-repository.git
remote: Repository not found.
fatal: repository 'https://github.com/our-organisation/some-repository.git/' not found

[某些名称可能已更改。]

当远程 URL 正确时,为什么 GitHub 会说“找不到存储库”?

标签: gitgithub

解决方案


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

我的一些同事很有帮助地建议我尝试使用 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,而不是 。403 Forbidden这是为了防止私有存储库意外泄漏给未经授权的用户。

-- GitHub

对我来说没有意义的是,当我使用 凭证助手通过 GitHub 进行身份验证 并且我可以访问该存储库(已成功克隆并获取它)时,GitHub 会因为缺少写权限而选择对我隐藏它的存在。

使用网络浏览器检查https://github.com/our-organisation/some-repository/确认我没有对存储库的写入权限。我们团队的 GitHub 管理员能够在短时间内授予我的团队写入权限,并且我能够将分支向上推。

希望这个问答对未来的人们有所帮助。


推荐阅读