Git克隆失败

fil*_*nut 5 git git-clone

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

该存储库位于Amazon的盒子上/home/ec2-user/my_test_repo.里面的my_test_repo目录是.git目录.

在我的OSX机器上,我可以成功SSH到托管repo的机器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
Run Code Online (Sandbox Code Playgroud)

我收到以下错误消息:

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.
Run Code Online (Sandbox Code Playgroud)

我在这里做错了什么想法?

Sto*_*ica 6

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

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.
Run Code Online (Sandbox Code Playgroud)

您需要首先使用此命令:

ssh ec2-user@ec2-54-81-229-189.compute-1.amazonaws.com
Run Code Online (Sandbox Code Playgroud)

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

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

git clone ssh://ec2-user@ec2-54-81-229-189.compute-1.amazonaws.com/home/ec2-user/my_test_repo/.git
Run Code Online (Sandbox Code Playgroud)

注意结束部分是my_test_repo/.git,因为它应该对应于包含Git存储库的目录的文件系统路径.一个Git仓库包含了诸如文件HEAD,config和目录,如objects,refs,hooks,和其他一些人.

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

git clone --bare my_test_repo my_test_repo.git
Run Code Online (Sandbox Code Playgroud)

执行此操作后,您的原始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
Run Code Online (Sandbox Code Playgroud)