git 无法识别远程存储库

git not recognizing remote repository

这整件事是因为我想将代码部署(并同步)到一个实时托管环境,用于我正在处理的网站(需要实际看到我正在做的更改)-路线, Bitbucket repo (code being worked on) -> local repo -> HostGator repo (results being visualized).

我在 Windows 上使用 Git Bash。我在 public_html 中的 HostGator 上有一个名为 "test" 的 git 存储库-已配置并且一切正常-我可以提交,分支等。 他们 (HostGator) 只允许在 SSH 连接上使用 port 2222。我创建了一个本地空存储库,然后将远程存储库添加到远程存储库列表中,如下所示:

git remote add localName ssh://username@address:2222/public_html/test 这是因为,尽我所能,我无法让 SSH 读取和应用我的本地配置文件。

然后为了测试一切正常我试过:

git ls-remote ssh://username@address:2222/public_html/test

此连接,要求输入密码,然后失败并显示 public_html/test is not a git repository 消息。我检查了权限,一切正常。

问题是:为什么会失败,无法识别版本库?我添加远程仓库的方式有问题吗?

编辑: 经过进一步调查,即使目录 test 是一个存储库并包含 .git 文件夹,git remote -v 显示没有“.git”的结束路径 'extension' - "public_html/test" 而不是 "public_html/test.git" ,第二个是存储库的正常路径。这让我相信添加它的语法不正确。

HostGator 中的 public_html 文件夹位于您的 HostGator 帐户主目录中。参见“public_html folder”:

尝试指定完整路径:

git remote add localName ssh://username@address:2222/home/username/public_html/test

也就是说,最好是:

  • 您的回购是 /home/username/test.git
  • 中的一个裸回购
  • 你有一个 post-receive 挂钩,它会检查 /home/public_html/test 中的回购内容(参见“GIT post-receive checkout without root folder”)

我的意思是,你可以 push to a non-bare repo(如果服务器上的 Git 足够新 2.3+),但最佳实践仍然是一个简单的 repo。