問題

由於公司訪問GitHub只能走代理,但是內網gitlab伺服器又不能走代理。

因此想找到一種方案,可以支援git自動根據專案地址使用不同代理。

方案

如下所示,可以指定GitHub地址使用指定的代理伺服器

git config --global http.https://github.com.proxy socks5://127.0.0.1:1081
git config --global http.https://github.com.sslVerify false
git config --global https.https://github.com.proxy socks5://127.0.0.1:1081
git config --global https.https://github.com.sslVerify false

.gitconfig檔案中配置如下:

[http "https://github.com"]
proxy = socks5://127.0.0.1:1081
sslVerify = false
[https "https://github.com"]
proxy = socks5://127.0.0.1:1081
sslVerify = false

總結

經過測試,不開代理伺服器時,可以從內網gitlab拉取專案和推送專案,拉取和推送GitHub專案會提示代理伺服器連不上。

開啟代理伺服器後,內網gitlab和GitHub均可以成功拉取專案和推送專案。