Git子模块等同于url.insteadof

时间:2017-06-27 19:27:02

标签: git git-submodules

我有几个Git存储库,它们都引用了一个或多个子模块,并且都是公司局域网/内部https URL(因此只能从公司域名访问)。

从外部/公共网络,ssh访问存储库是可能的,我可以减轻切换主存储库' URL通过全局.gitconfig url.insteadOf重定向来回传递,但是,相反的规则似乎并不适用于子模块(也是https网址)。

除了调整每个存储库的.git / config文件之外,还有其他方法...即我可以在全局.gitconfig中设置的内容吗?

2 个答案:

答案 0 :(得分:1)

我找不到使用git配置的方法,并且蛮力地去了:

# test step, replace the "url = https://github.com/" manually
# verify the desired effect
# note the comma in sed command, it's unusual and valid
sed 's,https://github.com/,git@github.com:,g' .git/modules/*/config | grep url
# -i to modify the files
sed -i 's,https://github.com/,git@github.com:,g' .git/modules/*/config

来自父存储库。

或如果不影响全局配置,请使用@torek的--global

git config --global url."git@github.com:".insteadOf "https://github.com/"
# or 
git config --global url."https://github".insteadOf git://github
# for reverse

答案 1 :(得分:1)

如果您对更改全局配置不满意,则可能需要分别配置每个子模块,因为每个子模块都是其自己的存储库。

幸运的是git提供了git submodule foreach命令,

  

在每个检出的子模块中评估一个任意的shell命令。

重要的是,它确实发生在每个检出的子模块中。 这意味着在运行git submodule update之前,某些子模块将被忽略。

所以

$ git config --local url."git@github.com:".insteadOf "https://github.com/"
$ git submodule foreach --recursive \
    'git config --local url."git@github.com:".insteadOf "https://github.com/"'

应该为主存储库,其子模块及其子模块的子模块解决问题。

相关问题