当前位置:   article > 正文

git 配置代理 >_>从此告别git clone几KiB/s了

git proxy 收费

windows 设置代理

http || https协议

  1. //设置全局代理
  2. //http
  3. git config --global https.proxy http://127.0.0.1:7891
  4. //https
  5. git config --global https.proxy https://127.0.0.1:7891
  6. // socks
  7. git config --global http.proxy socks5://127.0.0.1:7891
  8. git config --global https.proxy socks5://127.0.0.1:7891
  9. //只对github.com使用代理,其他仓库不走代理
  10. git config --global http.https://github.com.proxy socks5://127.0.0.1:7891
  11. git config --global https.https://github.com.proxy socks5://127.0.0.1:7891
  12. //取消github代理
  13. git config --global --unset http.https://github.com.proxy
  14. git config --global --unset https.https://github.com.proxy
  15. //取消全局代理
  16. git config --global --unset http.proxy
  17. git config --global --unset https.proxy

SSH协议

  1. //对于使用git@协议的,可以配置socks5代理
  2. //在~/.ssh/config 文件后面添加几行,没有可以新建一个
  3. //socks5
  4. Host github.com
  5. User git
  6. ProxyCommand connect -S 127.0.0.1:7891 %h %p
  7. //http || https
  8. Host github.com
  9. User git
  10. ProxyCommand connect -H 127.0.0.1:7891 %h %p

WSL2设置代理

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

其实上面地址就是windows下面这个ip地址image

我们要为WSL配置ssh代理和http代理

  1. touch ~/.ssh/config
  2. vim ~/.ssh/config
  3. Host github.com
  4. HostName github.com
  5. User git
  6. # 走 socks5 代理
  7. ProxyCommand nc -v -x 172.28.32.1:7891 %h %p

使用下面命令检查ssh代理配置是否成功image

可以将上面ip地址配置代理写入到.bashrc文件中,这样就可以自己用户开机永久生效

  1. host_ip=`cat /etc/resolv.conf|grep nameserver|awk '{print $2}'`
  2. sed -i "/.*ProxyCommand*/c\ ProxyCommand nc -v -x $host_ip:7891 %h %p" ~/.ssh/config
  3. export ALL_PROXY=http://$host_ip:7891
  4. export {http,https,ftp}_proxy=$ALL_PROXY
  5. export {HTTP,HTTPS,FTP}_PROXY=$ALL_PROXY

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

还需要将防火墙打开image

git push失败或者卡住不动问题

原因是有点节点22端口被服务端封锁了,需要更换443端口(~/.ssh/config))

  1. # 可以先使用如下测试下
  2. ssh -T -p 443 git@ssh.github.com
  3. # Hi USERNAME! You've successfully authenticated, but GitHub does not
  4. # provide shell access.
  5. # 更换端口后再测试下
  6. $ ssh -T git@github.com
  7. # Hi USERNAME! You've successfully authenticated, but GitHub does not
  8. # provide shell access.

image

参考链接

Git设置代理为 WSL2 一键设置代理WSL2配置代理wsl2 proxyHTTPS_PROXY vs https_proxygit-configSSH 防爆破与 Fail2Ban 加固解决 push 到 GitHub 异常 - 无法连接22端口Using SSH over the HTTPS port

声明:本文内容由网友自发贡献,转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号