Git 克隆失败

标签 git git-clone

我有一个基于 Linux 的 Amazon AMI,其中包含一个 Git 存储库。我想将该存储库 git clone 到我的本地 OSX 机器(也安装了 Git)。

存储库位于 /home/ec2-user/my_test_repo 的亚马逊盒子上。 my_test_repo 目录内是 .git 目录。

在我的 OSX 机器上,我可以通过 SSH 以 ec2-user 身份成功连接到托管存储库的机器,并且我可以执行许多 bash 命令。所以,我知道 SSH 有效。但是,当我从我的 OSX 机器上执行以下命令时,它不起作用:

git clone ssh://ec2-user@ec2-54-81-229-189.compute-1.amazonaws.com/home/ec2-user/my_test_repo.git

我收到以下错误消息:

Cloning into 'my_test_repo'...
Permission denied (publickey,gssapi-keyex,gssapi-with-mic).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.

知道我在这里做错了什么吗?

最佳答案

第一个问题是无法登录服务器:

Cloning into 'my_test_repo'...
Permission denied (publickey,gssapi-keyex,gssapi-with-mic).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.

你需要先让这个命令生效:

ssh ec2-user@ec2-54-81-229-189.compute-1.amazonaws.com

这个问题与Git无关,你需要让ssh使用公钥认证。

第二个问题是您的存储库路径可能是错误的。如果您在服务器上的存储库位于 .git 目录 inside /home/ec2-user/my_test_repo 中,那么 URL 将是:

git clone ssh://ec2-user@ec2-54-81-229-189.compute-1.amazonaws.com/home/ec2-user/my_test_repo/.git

注意结尾部分是 my_test_repo/.git,因为它应该对应于包含 Git 存储库的目录的文件系统路径。 Git 存储库包含 HEADconfig 等文件,以及 objectsrefshooks 和其他一些。

因此,看起来 my_test_repo 是一个所谓的工作树。如果您从 my_test_repo/.git 克隆,您将无法推送到它,因为 git 不允许推送到具有工作树的存储库。它只允许推送到所谓的裸存储库,没有工作树。您可以使用以下命令从现有的非裸存储库创建裸存储库:

git clone --bare my_test_repo my_test_repo.git

执行此操作后,您的原始 URL 应该有效,因为现在 Git 存储库的路径实际上是 my_test_repo.git,而不是 my_test_repo/.git。您不再需要 my_test_repo 工作树,可以将其删除。

最后,您可以像这样简化存储库 URL:

git clone ec2-user@ec2-54-81-229-189.compute-1.amazonaws.com:my_test_repo.git

关于Git 克隆失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23771644/

相关文章:

git - mac os zsh git-prompt.sh 无法使颜色正常工作

git - 在执行 git clone --mirror 时,实际文件在哪里?

gitlab错误从安装指南克隆git@localhost :gitolite-admin. git

使用公共(public)私钥的 Git 克隆

git - 重新创建 Gitolite-admin repo

git:重写历史:重新排序和 merge 提交

database - 如何将相关应用程序组织到 git repo 中?

git - 可以使用一个 SSH key 推送到不同的 Git 远程吗?

独立开发者的 GIT

c - 如何修复 `_meta' 的多个定义?