尝试通过SSH克隆时出现“不是git仓库”的错误信息

5

我有一台运行Windows 10的计算机,想在上面托管git存储库。OpenSSH正在运行,我能够通过Powershell连接到该计算机进行SSH连接。

我通过以下命令在Test文件夹中创建了一个新的git:

git init --shared --bare

我现在正在尝试使用Sublime Merge克隆源URL,如下所示:

ssh://USER@IP:/Test

然而,在输入密码后,我收到了两个错误:

fatal: "/Test" does not appear to be a git repository

fatal: Could not read from remote repository

我已经尝试了谷歌搜索这两个问题,但都没有找到任何有助的答案。有人能帮忙吗?

编辑:我可以在远程机器上克隆、提交和推送,所以它肯定是一个git仓库。

编辑 #2:问题已解决。按照此指南强制使用PowerShell(底部)将存储库直接指向git文件夹https://github.com/PowerShell/Win32-OpenSSH/wiki/Setting-up-a-Git-server-on-Windows-using-Git-for-Windows-and-Win32_OpenSSH

**Note that git clone user@domain@servermachine:C:/test/myrepo.git does not work due to known issue. Work around it to set powershell as default Shell in registry. Or by following steps when cmd is default shell:

cd c:\mygitrepros
# initialize a local repo folder
git init mylocalrepo
cd mylocalrepo
# add the remote repro
git remote add origin user@domain@servermachine:C:/test/myrepo.git
# work around the known issue by launching powershell to run the git commands
git config --local remote.origin.uploadpack "powershell git-upload-pack"
git config --local remote.origin.receivepack "powershell git-receive-pack"

拉取 origin 仓库代码到本地


1
文档中不推荐使用“--shared”,除非您知道自己在做什么。它也仅适用于本地克隆,即不通过ssh。 - EncryptedWatermelon
谢谢你提醒我。 - selfname
1
SSH服务器通常从特定用户的目录开始文件访问,因此ssh://user@ip/foo表示“用户user的主目录中的文件foo”。要访问/Test,您需要ssh://user@ip//Test - torek
@torek 看起来 Windows 可能是证明这个规则的例外 :/ - CervEd
@CervEd:通常情况下,Windows是稳定的。但是这个“已知问题”(https://github.com/PowerShell/Win32-OpenSSH/issues/895)自2017年以来就一直存在,这似乎有点奇怪! - torek
1个回答

2
这里有一个完整的教程,介绍如何加速仓库。原始答案翻译成“最初的回答”。您可以在以下链接中找到该教程:https://git-scm.com/book/en/v2/Git-on-the-Server-Setting-Up-the-Server。虽然该教程是针对Linux操作系统的,但我认为步骤应该类似。当您使用以下命令创建一个裸仓库时:
$ cd /srv/git
$ mkdir project.git
$ cd project.git
$ git init --bare
Initialized empty Git repository in /srv/git/project.git/

通常情况下,文件夹会被命名为.git。但是在那之后,你应该能够使用以下命令进行克隆。最初的回答。
git clone git@gitserver:/srv/git/project.git

所以你需要添加Git文件夹的路径。我认为这就是你的问题。你只尝试了从你的根目录中的路径"/Test",但这可能是错误的,Git会告诉你这个文件夹不是一个Git仓库。最初的回答。

我原本以为git文件夹在根路径下。你知道这个路径是C:/,C:/Users/UserName还是Windows 10中的其他路径吗? - selfname
我只使用Linux,不清楚Windows上是否有很多Git服务器。也许你可以安装像gitea这样的系统,然后你就有了一个平台,在那里你可以添加仓库并获得所需的一切。 - René Höhle
我一定会研究Gitea。我不确定是否是路径问题,因为现在我只是尝试使用完整路径(基于https://dev59.com/H5nga4cB1Zd3GeqPXVkm),但它仍然会抛出错误:`git clone ssh://USER@IP:/C/FOLDER/Test.git`。 - selfname
1
如果你好奇的话,这绝对是一个路径问题(我仍然不知道服务器上的默认路径是什么)。按照此链接中概述的步骤进行操作,并能够明确指向C:/FOLDER/Test.git并成功拉取它:https://github.com/PowerShell/Win32-OpenSSH/wiki/Setting-up-a-Git-server-on-Windows-using-Git-for-Windows-and-Win32_OpenSSH - selfname

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