git根据项目地址使用不同代理服务器

问题

由于公司访问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均可以成功拉取项目和推送项目。

posted @ 2021-08-19 19:44  janbar  阅读(248)  评论(0编辑  收藏  举报