将Git Remote添加到不同的目录 [英] Adding Git Remote to Different Directory

查看:122
本文介绍了将Git Remote添加到不同的目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我正在编写一个脚本,用于初始化〜/ .cfi 中的git存储库,添加一个远程服务器,并从服务器上拉下。

b
$ 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 for git pull. Is there a simple way to execute these two commands on the above directory without cding 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 "Use git 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆