给 Git 设置 HTTP / SOCKS5 代理

admin 2023年12月26日14:23:45系统文档评论1,192 次浏览阅读模式

在最近,博主在调试脚本项目的时间中,使用Git拉取源码就会出现以下错误

仔细检查了下原因,发现是Git拉取的GitLab仓库没走系统代理。在这一篇教程中,我来和大家一起来解决这个问题

准备材料

HTTP / SOCKS5 代理

设置 HTTP 代理

1
2
3
4
// 通过 http 链接 clone 代码时走 http 代理
git config --global http.proxy "http://127.0.0.1:6666"
// 通过 https 链接 clone 代码时走 http 代理
git config --global https.proxy "http://127.0.0.1:6666"

将127.0.0.1:6666替换成实际的代理地址

设置 SOCKS5 代理

1
2
3
4
// 通过 http 链接 clone 代码时走 socks5 代理
git config --global http.proxy "socks5://127.0.0.1:6666"
// 通过 https 链接 clone 代码时走 socks5代理
git config --global https.proxy "socks5://127.0.0.1:6666"

将127.0.0.1:6666替换成实际的代理地址

这些设置最终会保存在用户目录下的 .gitconfig 文件中,打开这个文件可以看到类似的几行配置

1
2
3
4
[http]
proxy = http://127.0.0.1:6666
[https]
proxy = http://127.0.0.1:6666

如果端口有变动可以直接在这里修改,也可以使用之前的命令再次设置。

参考文章

https://imciel.com/2016/06/28/git-proxy

相关文章
weinxin
我的微信
微信扫一扫
admin
  • 本文由 发表于 2023年12月26日14:23:45
  • 转载请务必保留本文链接:http://anyun.org/a/jishuguanzhu/xitongwendang/2023/1226/15730.html

发表评论

匿名网友 填写信息

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: