简体   繁体   English

Git push ssh失败,使用远程URL而不是原始名称--(错误:未找到存储库)

[英]Git push over ssh fails using remote url instead of origin name - (ERROR: Repository not found)

Hi I have setup Git/Github with SSH successfully. 嗨,我已经用SSH成功​​设置了Git / Github。 I know this because I went through the Github help guide to check this and all results passed OK. 我知道这一点是因为我仔细阅读了Github帮助指南,并检查了所有结果。

I can push to my Github repo using the following command for a tag example: 我可以使用以下命令作为示例来推送到我的Github存储库:

git push origin <tagname>

However, when I try to do the same thing but specify the remote by url, it fails telling me that the repo does not exist: 但是,当我尝试执行相同的操作但通过url指定远程服务器时,它无法告诉我该存储库不存在:

git push git@github.com:<organisationname>/<reporname>.git <tagname>

I get the following error: 我收到以下错误:

ERROR: Repository not found. 错误:找不到存储库。 fatal: Could not read from remote repository. 致命:无法从远程存储库读取。

Please make sure you have the correct access rights and the repository exists. 请确保您具有正确的访问权限,并且存储库存在。

The documentation for git push does support both syntax so I'm stumped as to why the URL version fails and the "origin" version does not? git push文档不支持这两种语法,因此我很困惑为什么URL版本失败而“ origin”版本却不支持?

I found the issue and it was actually a simple one. 我发现了这个问题,它实际上是一个简单的问题。 The user configured for the release plugin was different to the user configured for access to the repos. 为发布插件配置的用户与为访问回购协议配置的用户不同。 In my question I have an example including "git" as the user, which actually did not represent the URL used by the maven plugin, it was using a different user. 在我的问题中,我有一个示例,其中包括“ git”作为用户,它实际上并不代表maven插件使用的URL,而是使用了另一个用户。

So for clarity, if ssh access was based on "user1" and maven release plugin was configured to run with "user2" then that's when I get the failed push. 因此,为清楚起见,如果ssh访问基于“ user1”,并且maven版本插件配置为与“ user2”一起运行,那么这就是我收到失败的推送的时间。

To handle this in a user ambiguous way the git docs suggests always pushing using the "git" user. 为了以一种用户含糊的方式处理此问题,git文档建议始终使用“ git”用户进行推送。

For example, even with an ssh key setup for "user1", in my setup the following push was still successful: 例如,即使使用“ user1”的ssh密钥设置,在我的设置中,以下推送仍然成功:

git push git@github.com:<organisationname>/<reporname>.git <tagname>

But the following is not: 但是以下不是:

git push user2@github.com:<organisationname>/<reporname>.git <tagname>

Now I know the reason, its pretty obvious and feels silly that I missed that in my config originally. 现在我知道了原因,它很明显,并且感到很愚蠢,因为我最初在我的配置中错过了它。 This also explains why the original question if run on any repo setup with proper ssh keys works fine, as the comments suggest. 这也解释了为什么原始问题(如果在带有适当的ssh密钥的任何回购设置上运行)可以正常工作,如评论所建议的那样。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM