无法克隆Git存储库,似乎不是Git存储库。致命错误:无法从远程存储库读取。

3

我正在按照Git文档的步骤,在本地电脑上创建一个远程服务器上的代码库:

$ git clone --bare my_project my_project.git

我已经将代码库复制到服务器上。
$ scp -r my_project.git myuser@myip:/opt/git

但是如果我尝试克隆

git clone myuser@myip:/opt/git/my_project.git

我明白了

fatal: 'opt/git/my_project.git' does not appear to be a git repository
fatal: Could not read from remote repository.

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

我原以为是权限问题,但如果我使用 ssh myuser@myip 进行连接,则可以自由创建文件或进行任何操作,该文件夹属于 myuser 用户。


这个语法对我来说似乎可以工作(尽管使用scp而不是git push有点奇怪)。但是如果你看一下错误信息,就会发现缺少前导/。由于某些原因,我不清楚git相对于myuser的主目录寻找opt/git/my_project.git,而不是它所在的/opt/git/my_project.git。换句话说,我可能漏掉了一点。版本?也许尝试在名称前加上ssh://方案,以防名称中的某些内容引起麻烦? - Ondrej K.
谢谢,但我已经解决了。 - afdi2
3
如果是这样,你可能希望分享你的发现,以便未来的读者能够受益。 - Ondrej K.
1个回答

1
首先,通过运行以下命令检查您的起始点是否设置:

git remote -v

这应该向您展示项目的所有推送/拉取远程。
如果没有输出返回,请跳到最后一个代码块。
验证远程名称/地址
如果返回显示您已设置远程,请检查远程的名称是否与您在命令中使用的远程相匹配。
$git remote -v
myOrigin ssh://git@example.com:1234/myRepo.git (fetch)
myOrigin ssh://git@example.com:1234/myRepo.git (push)

# this will fail because `origin` is not set
$git push origin master

# you need to use
$git push myOrigin master

如果您想重命名远程或更改远程的URL,则需要首先删除旧的远程,然后添加正确的远程。
删除旧的远程。
$git remote remove myOrigin

添加缺失的远程仓库

然后您可以使用以下命令添加正确的远程仓库:

$git remote add origin ssh://git@example.com:1234/myRepo.git

# this will now work as expected
$git push origin master

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