Loading

Git针对指定网站设置代理

我们经常要用到各种git地址,比如github、gitee还有自己搭建的git等等。

但是github我们经常拉取和推送代码的时候超时,这时候如果我们搜索会发现大量的文章都是告诉我们设置全局系统代理:

使用http代理

git config --global http.proxy http://127.0.0.1:7890
git config --global https.proxy https://127.0.0.1:7890

使用socks5代理

git config --global http.proxy socks5://127.0.0.1:7891
git config --global https.proxy socks5://127.0.0.1:7891
这种方式会让我们所有的git请求都走代理,但是我们访问gitee肯定不需要代理啊,走代理反而会慢。

所以我们需要针对github单独设置代理。

我们可以这么干。

使用socks5代理(推荐)

git config --global http.https://github.com.proxy socks5://127.0.0.1:7891
git config --global https.https://github.com.proxy socks5://127.0.0.1:7891

使用http代理(不推荐)

git config --global http.https://github.com.proxy http://127.0.0.1:7890
git config --global https.https://github.com.proxy https://127.0.0.1:7890
这样就会只有网址是https://github.com的时候走我们指定的git代理,剩下的不走,完美解决了我们的问题。

如果我们要取消使用代理,可以设置

git config --global --unset http.proxy
git config --global --unset https.proxy

posted @ 2025-12-11 14:25  oaifree  阅读(49)  评论(0)    收藏  举报