git为github设置代理的优雅方式

git为github设置代理的优雅方式,第1张

方案:在地址前加 https://github.91chi.fun/

如: git clone https://github.com/hybridgroup/gocv.git

改为: git clone https://github.91chi.fun/https://github.com/hybridgroup/gocv.git

ps: 需要根据个人情况设置好端口号,如果是sock,则把https或http换为sock

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

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

即这种形式clone下来的仓库:

git clone [email protected]:hybridgroup/gocv.git

PS: 方式3参考了: Issue #1563 · Fndroid/clash_for_windows_pkg (github.com)

对于 git, 只需要用下面的明亮就可以了

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

git config --global https.proxy https://127.0.0.1:1080

git config --global http.proxy 'socks5://127.0.0.1:1080'

git config --global https.proxy 'socks5://127.0.0.1:1080'

如果想要取消:

git config --global --unset http.proxy

git config --global --unset https.proxy

但是如果是vscode,同样也是通过首选项->设置->搜索proxy,然后可以输入上面的proxy。速度就飞了。。

或者可以这样:

export https_proxy=http://127.0.0.1:4780 http_proxy=http://127.0.0.1:4780 all_proxy=socks5://127.0.0.1:4780

当然,自备梯子

Git 平常使用最多的是 SSH 协议和 HTTP(S) 协议,假设本地 1080 端口有一个 socks5 代理服务器,就要为这两个协议分别设置代理。

HTTP(S) 协议:

全局代理:

git config --global http.proxy socks5://127.0.0.1:1080

只对特定 URL 设置代理:

git config --global http.<要设置代理的URL>.proxy socks5://127.0.0.1:1080

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

SSH 协议:

SSH 协议相对复杂,需要安装一个代理协议转换工具 connect ,从这里获取源代码,用 gcc 编译即可,注意 Mac 下可能需要注释掉1765行才能编译通过。

修改 ~/.ssh/config 加入如下内容

全局代理:

ProxyCommand connect -S 127.0.0.1:1080 %h %p

只对特定域名进行代理:

Host 域名

ProxyCommand connect -S 127.0.0.1:1080 %h %p

Host github.com

ProxyCommand connect -S 127.0.0.1:1080 %h %p


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/tougao/6560626.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-03-24
下一篇 2023-03-24

发表评论

登录后才能评论

评论列表(0条)

保存