我有一个项目,我创建了一个git存储库:

$ cd myproject  
$ git init  
$ git add .  
$ git commit  

我想在另一台机器上创建一个裸克隆:

$ cd ..  
$ git clone --bare myproject  ssh://user@server:/GitRepos/myproject.git  

我执行了克隆,但没有打印任何答案。 我登录到服务器上,试图查看文件是如何存储的。路径/GitRepos是空的,所以我决定再次克隆:

$ git clone --bare myproject  ssh://user@server:/GitRepos/myproject.git

这一次的答案是:

ssh://user@server:/GitRepos/myproject。Git目录已经存在,并且不是空目录。

但我看到小路上空无一人。 这是怎么回事?


当前回答

围棋 101:

Git是一个去中心化的版本控制系统。你不需要服务器来启动和运行git。你可能还是想这么做,因为它看起来很酷,对吧?(如果你想在多台电脑上处理一个项目,它也很有用。)

所以要让“服务器”运行,你需要运行git init——bare <your_project>。Git会创建一个空的存储库,然后你可以将它导入到你的机器上,而不必在. Git目录下的配置文件中瞎折腾。

After this you could clone the repo on your clients as it is supposed to work, but I found that some clients (namely git-gui) will fail to clone a repo that is completely empty. To work around this you need to run cd <your_project>.git && touch <some_random_file> && git add <some_random_file> && git commit && git push origin master. (Note that you might need to configure your username and email for that machine's git if you hadn't done so in the past. The actual commands to run will be in the error message you get so I'll just omit them.)

因此,在这一点上,你可以简单地运行git clone <user>@<server>:<relative_path><your_project>.git将存储库克隆到任何机器。(正如其他人指出的那样,如果使用绝对路径,可能需要在它前面加上ssh://。)这假设您已经可以从客户端登录到服务器。(如果你想把很多东西推送到远程服务器上,你还可以为ssh设置配置文件和密钥。)

相关链接: 这基本上告诉了你你需要知道的。 这是为那些知道git的基本工作原理但有时忘记确切语法的人准备的。

其他回答

我说: “/GITREPOSITORIES/RepoA”“ssh://luc@EERSTENASDS119J/volume1/RepoA” 结果: fatal:目标路径“ssh://luc@EERSTENASDS119J/volume1/RepoA”已经存在,并且不是空目录。

系统在当前路径下创建了一个目录ssh://luc@EERSTENASDS119J/volume1/RepoA。

所以git克隆没有解释URL规范。 使用亚历克的变通方法。

围棋 101:

Git是一个去中心化的版本控制系统。你不需要服务器来启动和运行git。你可能还是想这么做,因为它看起来很酷,对吧?(如果你想在多台电脑上处理一个项目,它也很有用。)

所以要让“服务器”运行,你需要运行git init——bare <your_project>。Git会创建一个空的存储库,然后你可以将它导入到你的机器上,而不必在. Git目录下的配置文件中瞎折腾。

After this you could clone the repo on your clients as it is supposed to work, but I found that some clients (namely git-gui) will fail to clone a repo that is completely empty. To work around this you need to run cd <your_project>.git && touch <some_random_file> && git add <some_random_file> && git commit && git push origin master. (Note that you might need to configure your username and email for that machine's git if you hadn't done so in the past. The actual commands to run will be in the error message you get so I'll just omit them.)

因此,在这一点上,你可以简单地运行git clone <user>@<server>:<relative_path><your_project>.git将存储库克隆到任何机器。(正如其他人指出的那样,如果使用绝对路径,可能需要在它前面加上ssh://。)这假设您已经可以从客户端登录到服务器。(如果你想把很多东西推送到远程服务器上,你还可以为ssh设置配置文件和密钥。)

相关链接: 这基本上告诉了你你需要知道的。 这是为那些知道git的基本工作原理但有时忘记确切语法的人准备的。

对于GitHub上的存储库,请尝试:

git clone ssh://git@github.com/<user>/<repository name>.git

通过ssh设置git克隆参见:

生成SSH密钥并在“帐户设置-> SSH密钥”中添加生成的密钥 SSH克隆

免责声明:这只是bobbaluba评论的副本,以便将来的访问者更容易看到。这比其他任何答案都更有用。


以git clone为例,必须去掉ssh://前缀

git clone git@github.com:owner/repo.git

做这个问题很简单 试试这个。

步骤1:

ls -al ~/.ssh

步骤2:

ssh-keygen 

(使用enter键作为默认值) 步骤3:设置配置文件

vim /c/Users/Willie/.ssh/config

主机gitlab。com 主机gitlab。com git用户 IdentityFile ~ / . ssh / id_rsa

步骤4:

git clone git@gitlab.com:<username>/test2.git

步骤5: 当你完成第四步的时候 1.test2。Git文件将下载完成 2.您将在~/.ssh中获得新文件(known_hosts)

PS:我创建了id_rsa和id_rsa。并将其交付到Gitlab服务器。在任何客户端(windows和Linux)使用这两个密钥。