我在使用 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
有任何想法吗?
git remote remove origin
git remote add origin https://[USER]:[TOKEN]@github.com/[USER]/[REPO]
git push
git clone https://[USER]:[TOKEN]@github.com/[USER]/[REPO]
远程:仓库未找到。
这是从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而非SSH。
我知道,GitHub在某些情况下将“Forbidden”替换为“Not Found”,以防止意外地揭示私有存储库的存在。
需要身份验证的请求将在某些地方返回
404 Not Found
,而不是403 Forbidden
。这是为了防止私有存储库意外泄露给未经授权的用户。
-- GitHub
这在网上是相当常见的做法,的确已经被定义:
404 (Not Found)
状态代码表示:源服务器没有找到目标资源的当前表示形式,或者不愿透露其存在。
--6.5.4. 404 Not Found, RFC 7231 HTTP/1.1 Semantics and Content (我强调)
对我来说毫无意义的是,当我使用凭证助手进行GitHub身份验证,并且我可以访问该存储库(已经成功克隆和获取了它)时,GitHub竟然会因为缺少写权限而选择将其隐藏。
使用Web浏览器检查https://github.com/our-organisation/some-repository/确认我没有写入该存储库的权限。我们团队的GitHub管理员很快就能授权我的团队进行写操作,我也能够将分支推送上去。
git push https://youruser:password@github.com/user/reponame.git
用户名和密码
需要进行URL编码,因此@应该被替换为%40等等。
eval "$(ssh-agent -s)"
,然后 ssh-add ~/.ssh/<key_of_user>
。 - Francois$ git remote rm origin
$ git remote add origin git@github.com:<USER>/<REPO>.git
如果您的SSH密钥已在其他Github仓库中使用,您可以生成一个新的。
2. 生成新的SSH密钥
$ ssh-keygen -t rsa -b 4096 -C "web@github.com"
3. 在SSH代理级别添加密钥
$ eval "$(ssh-agent -s)"
$ ssh-add ~/.ssh/id_rsa_github
4. 将新key添加到Github仓库。
可能有一个问题,对一些人来说很明显但我没有看到在这里提到,那就是你使用ssh密钥访问,但你正在尝试通过https连接本地仓库到远程仓库。
如果是这种情况,则以下命令应该可以解决问题:
$ git remote -v
origin https://github.com/private-repo.git (fetch)
origin https://github.com/private-repo.git (push)
$ git remote rm origin
$ git remote add origin git@github.com:private-repo.git
$ git remote -v
origin git@github.com:private-repo.git (fetch)
origin git@github.com:private-repo.git (push)
请注意,上述内容假定以下情况成立:origin
,您已经生成了与您的github账户连接的ssh密钥。
2. 您已经有一个与您的github账户关联的ssh密钥(并在本地连接)。
3. 您已经在github上为此仓库设置了正确的权限(读/写)。遇到了类似的问题。问题的根源是我按照一些关于在Github上添加新存储库的在线教程操作。
只需前往Github,创建一个新仓库,它将要求您添加README文件,不要添加它。创建它,您将获得有关如何推送的说明。
这类似于接下来的两行:
git remote add origin https://github.com/YOUR_USER/your-repo.git
git push -u origin master
如果你属于 Github 上的一个团队,请检查你是否具有写入权限。
我在MAC上试图从一个之前连接过的私有仓库拉取代码时遇到了同样的问题。
我通过在仓库链接中包含我的用户名来解决了这个问题:
git remote set-url origin https://<YOUR_USER_NAME_HERE>@github.com/<YOUR_USER_NAME_HERE>/<REPO>.git
然后我成功从代码库中拉取了代码。
如果您要克隆一个新的代码库:
git clone https://<YOUR_USER_NAME_HERE>@github.com/<YOUR_USER_NAME_HERE>/<REPO>.git
它会提示您输入该账户的密码,之后您就可以使用它了。
git pull https://myusername:mypassword@github.com/path_to/myRepo.git
git config --global --unset credential.helper
git remote add origin git@github.com:account-name/repo-name.git
的方式。它存在于GitHub上,是一个私有仓库。 - Justin[remote "origin"]
部分的URL键中。 - Ahmed Jehanzaib