带有子模块的项目的 git config 代理

Rob*_*_UK 1 git settings configuration proxy git-submodules

我有以下项目设置

ProjectA  
    -- [sub moduleB]
       -- file1
       -- file2 etc
    -- [sub moduleC]
  --file1
  --file2
  --etc
Run Code Online (Sandbox Code Playgroud)

ProjectA是它自己的项目。子模块也是如此。每个都有自己的文件和文件夹以及 git 存储库。然而,我遇到的问题是,由于公司限制,子模块中的内容要求我通过代理连接到它。例如,ProjectA 是内部托管的,但子模块不是。将子模块视为更大应用程序的外部插件。

我目前通过手动设置代理来解决这个问题。

所以在projectA中我通过输入清除代理设置

git config --global http.proxy ""
Run Code Online (Sandbox Code Playgroud)

当我在子模块中时,我设置代理

git config --global http.proxy http://<proxy url>:8080
Run Code Online (Sandbox Code Playgroud)

我可以配置 git 以记住文件夹级别的代理吗?所以我不必一直记住(有时忘记)来运行这个配置命令。我想只做一次,然后就忘记它。

And*_*w C 5

免责声明 - 我没有与您类似的环境来测试它

当你配置类似的东西时

git config --global
Run Code Online (Sandbox Code Playgroud)

上面--global说“将此配置值放入.gitconfig我的主目录中的文件中”。Git 将您的家庭版本应用.gitconfig到您访问的所有存储库。如果你要像这样配置

git config http.proxy http://your.proxy:8080
Run Code Online (Sandbox Code Playgroud)

它将配置条目放置在当前存储库配置文件中,该文件位于 $REPO/.git/config 中。因此,在您的实例中,在每个子模块中设置 http.proxy,但让 http.proxy 在超级项目或您的家庭配置中没有价值可能会成功。

所以全局取消设置

git config --global --unset http.proxy 
Run Code Online (Sandbox Code Playgroud)

然后导航到每个子模块并执行

git config http.proxy http://your.proxy:8080
Run Code Online (Sandbox Code Playgroud)