将git克隆到主目录下

14
$ git clone ssh://host/repo.git ~/
destination directory '/home/username/' already exists.

有人能告诉我如何使这个工作?我想快速地复制常见的开发脚本和配置。


1
git clone 会在工作路径下创建一个新目录,或者在指定的路径下创建。由于 ~/ 已经存在,它无法创建一个新的目录... - Karl Barker
1
你真的想从 git 存储库中拉取整个主目录吗?还是只想拉取到子目录中? - Kevin Hughes
1
是的,存储库中的所有文件都属于主目录。 - rich
4个回答

35

这似乎有效:

cd ~
git init
git remote add origin ssh://host/repo.git
git pull origin master

2
克隆命令会在传递第二个参数时创建一个新目录:
$ git clone ssh://host/repo.git ~/your_directory

clone 命令会创建一个名为 ~/your_directory 的目录。如果该目录已经存在,则会返回相应的错误信息。


@rich 只需像我的示例一样给出目录名称,或者执行 cd ~ && git clone ssh://host/repo.git 命令。 - ouah

1
cd ~
git clone ssh://host/repo.git

接下来,您的项目位于/home/username/repo/目录中。

如果您希望将项目放置在不同的文件夹名称下(例如'foo /')

mkdir ~/foo
cd ~/foo
git clone ssh://host/repo.git foo/

我想要在主目录中检查它。 - rich

-1

我会将存储库克隆到子目录中:

git clone ssh://your/git/repo.git ~/repo

并创建符号链接到配置文件:

ln -s ~/repo/.bashrc ~/.bashrc

2
这将会是一个噩梦,如果我想将它克隆到每台机器上,就必须为仓库中的每个文件执行此操作。 - rich
1
当然,但你也可以为此创建一个shell脚本.. Github示例 - T. Zengerink

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