将Git Remote添加到不同的目录 [英] Adding Git Remote to Different Directory
问题描述
因此,我正在编写一个脚本,用于初始化〜/ .cfi
中的git存储库,添加一个远程服务器,并从服务器上拉下。
$ b
创建目录,并初始化存储库工作正常。问题是添加远程并执行pull操作。
从文档看,它不像 git remote add
有一个目录参数。同样的 git pull
。有没有一种简单的方法可以在上面的目录中执行这两个命令而不需要 cd
到它?
是的,使用 - git-dir
和 - 工作树
选项。
自git 1.8.5以来,您甚至可以使用 -C
(更短的选项)。
请参阅在其他文件夹中使用 git log
命令
git --git-dir = / path / to / repo / .git --work-tree = / path / to / repo remote添加xxx
git --git-dir = / path / to / repo / .git --work-tree = / path / to / repo pull
或者:
git -C / path / to / repo remote add xxx
git -C / path / to / repo pull
So I am writing a script that initializes a git repository in
~/.cfi
, adds a remote, and pulls it down from the server.Creating the directory, and initializing the repository work fine. The issue is adding the remote and doing a pull.
From the documentation, it doesn't look like
git remote add
has a directory parameter. Same goes forgit pull
. Is there a simple way to execute these two commands on the above directory withoutcd
ing to it?解决方案Yes, with the
--git-dir
and--work-tree
options.And since git 1.8.5, you even can use
-C
(shorter option).
See "Usegit log
command in another folder"git --git-dir=/path/to/repo/.git --work-tree=/path/to/repo remote add xxx git --git-dir=/path/to/repo/.git --work-tree=/path/to/repo pull
Or:
git -C /path/to/repo remote add xxx git -C /path/to/repo pull
这篇关于将Git Remote添加到不同的目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!