Fork me on GitHub

Git 配置代理

使用 git clone 下载 Github 等网站的仓库时,可能会遇到类似 "Recv failure: Connection was reset" 或 "Failed to connect to http://github.com port 443 after 21114 ms: Couldn't connect to server" 的报错。即使打开了全局代理,也会报错。此时,需要为 Git 单独配置代理,可以使用以下命令:

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

配置完成后,可以使用以下命令查看并修改 Git 的配置:

git config --global --edit

此时 Git 的默认编辑器会打开 ~/.gitconfig 文件,其中包括了代理的配置:

[http]
	proxy = http://127.0.0.1:7890
[https]
	proxy = http://127.0.0.1:7890

这样就完成了配置,可以 clone 一个仓库来测试,比如:

git clone https://github.com/github/gitignore.git

如果仍然报错,可以检查代理端口是否配置正确,并尝试用以下命令设置关闭 SSL 证书验证:

git config --global http.sslVerify false

关于 Git 配置的更多信息,请阅读 Git - git-config Documentation

来源:https://zhuanlan.zhihu.com/p/648164862

posted @   会自愈的哈士奇  阅读(412)  评论(1编辑  收藏  举报
相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)
点击右上角即可分享
微信分享提示