将远程配置提交到 git 存储库?

Committing a remote configuration to a git repository?

我很确定我知道这个问题的答案,我可以 "preset"(即提交)远程到 Git 存储库,以便在克隆它时,克隆的存储库也有遥控器不用remote add吗?

这是用例。我想分叉节点并进行只有我的团队需要的更改(即,不适合合并回上游存储库)。我还希望我的团队能够定期合并来自原始存储库的新更改。换句话说:

  1. 在 github.com 上:分叉 github.com/joyent/node → github.com/[我]/节点
  2. 在我的本地机器上:git clone https://github.com/[me]/node.git
  3. 在我的本地机器上:git add remote upstream https://github.com/joyent/node.git
  4. [branch, hack, merge, fetch upstream, push, 等等]...

到目前为止一切顺利。

真正想要的是 "commit" 和 "push" upstream 远程配置,这样下次有人 git clone https://github.com/[me]/node.git,他们不必也做 git add remote upstream https://github.com/joyent/node.git(即,它已经为克隆的存储库设置)。

我看到 git 有一个专门的概念,可以提交子模块配置(请参阅 gitmodules[5]),但我找不到用于任意配置覆盖的通用选项。我意识到这可能是设计使然,因为它有误用的风险(想象一下 user.email 的预设覆盖)。

感谢任何帮助,即使只是:"Nope, sorry. Your team is going to have to type git add remote upstream ... for every cloned repo. [Citation.]"

提交这个问题几分钟后,我找到了 this question and answer(我在最初的搜索中没有找到)。

基本上,它说每个克隆的回购协议 git add remote upstream ... 必须是 运行,(或者必须编辑 .git/config)。正如@AndrewC 指出的那样,这可以通过 [wrapper] 脚本自动完成。

这对我来说似乎很笨拙,但我承认修复 upstream 遥控器可能是个坏主意。