git设置代理+wsl2设置代理

发布时间 2023-09-06 22:36:24作者: eehongzhijun

1.http || https协议

//设置全局代理
//http
git config --global https.proxy http://127.0.0.1:1080
//https
git config --global https.proxy https://127.0.0.1:1080
//使用socks5代理的 例如ss,ssr 1080是windows下ss的默认代理端口,mac下不同,或者有自定义的,根据自己的改
git config --global http.proxy socks5://127.0.0.1:1080
git config --global https.proxy socks5://127.0.0.1:1080

//只对github.com使用代理,其他仓库不走代理
git config --global http.https://github.com.proxy socks5://127.0.0.1:1080
git config --global https.https://github.com.proxy socks5://127.0.0.1:1080
//取消github代理
git config --global --unset http.https://github.com.proxy
git config --global --unset https.https://github.com.proxy

//取消全局代理
git config --global --unset http.proxy
git config --global --unset https.proxy

2.SSH协议

//对于使用git@协议的,可以配置socks5代理
//在~/.ssh/config 文件后面添加几行,没有可以新建一个
//socks5
Host github.com
User git
ProxyCommand connect -S 127.0.0.1:1080 %h %p

//http || https
Host github.com
User git
ProxyCommand connect -H 127.0.0.1:1080 %h %p

3.WSL2工具设置代理

在 Ubuntu 子系统中,通过 cat /etc/resolv.conf 查看 DNS 服务器 IP
image

可以看到 DNS 服务器是 172.28.32.1,通过环境变量 ALL_PROXY 配置代理:

export ALL_PROXY="http://172.28.32.1:7891"

7891端口是clash for windows端口,另外将Allow LAN打开
image

还需要将防火墙打开
image

参考链接

Git设置代理
为 WSL2 一键设置代理
WSL2配置代理