开启clash代理git访问github还是很慢

如何开启

可能是因为git没有走代理,可做如下设置

# 若希望只对单个项目生效则不要 --global
git config --global http.proxy "socks5://127.0.0.1:7890"
git config --global https.proxy "socks5://127.0.0.1:7890"

取消代理

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

其中 7890 是clash设置的代理端口

或者只针对github单独配置(因为也可能使用其他的git远程仓库,如gitee)

# 添加代理
git config --global http.https://github.com.proxy socks5://127.0.0.1:7890

# 取消代理
git config --global --unset http.https://github.com.proxy

如果想对单个项目使用代理,则去除上述命令中的 --global 即可

如何验证

关闭clash,再进行提交或拉取代码,若设置了代理则会提示拒绝连接

开启clash后再次提交发现没问题了就说明代理设置成功了

还是没效果?

不知道你们什么情况,我根据上述方法测试后发现,即使确定使用了代理也经常会遇到dns解析或超时等问题,新的解决方案是使用 socks5h 代理,这里的 h 即 host,表示域名解析也走该代理(socks5a也是一样),否则就是使用本地配置的dns进行解析。

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

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

CMD怎么配置

在需要设置代理的cmd窗口输入命令

set http_proxy=http://127.0.0.1:7890
set https_proxy=http://127.0.0.1:7890

注:这个做法只对该cmd窗口生效,其他的窗口或关闭该窗口均无效

使用curl进行验证:

curl google.com

1 thought on “开启clash代理git访问github还是很慢”

Leave a Comment