关于git clone时遇到的超时问题

发布于 2024-01-31  842 次阅读


报错提示

最近在使用GitBash用git clone克隆GitHub上的实验室项目时发现总是超时,梯子也有开着,网页也可以进,就是clone不下来:

git clone https://github.com/xxx.git
Cloning into 'xxx'...
fatal: unable to access 'https://github.com/xxx.git/': Failed to connect to github.com port 443: Timed out

说的就是连接443端口失败,失败原因是超时。443端口就是HTTPS的网页浏览端口,说明git访问这个网页超时,但是我们其实挂梯子其实可以成功访问github.com的。

这个主要就是因为我们用了代理服务器来加速访问github,但是git clone没有配置代理导致的连接超时

解决方法

配置git的代理:

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

注意其中的7890端口号需要更换你自身使用的代理的端口号

配置好之后使用https的方式重新git clone就可以啦:

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