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均可以成功拉取项目和推送项目。

作者:janbar
本文版权归作者和博客园所有,欢迎转载,转载请标明出处。喜欢我的文章请 [关注我] 吧。
如果您觉得本篇博文对您有所收获,可点击 [推荐] [收藏] ,或到右侧 [打赏] 里请我喝杯咖啡,非常感谢。
原文地址:https://www.cnblogs.com/janbar/p/15163580.html