git clone 失败的两种解决办法(适用于 WSL)

最近不知道北京的网怎么了,github 又上不去了。

对于我的 windows 本机,开着 clash 可以用浏览器上 github,但是 git clone 还是不行。

WSL(我的装了 ubuntu 20.04)就更不行了。

网上搜了一圈,找到了:https://zhuanlan.zhihu.com/p/659727636


考虑在本机上用第一个方法(clash 的端口是 7890,要改一下):

终端输入:

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

原理就是让 git clone 的包走 7890 端口发。

这个方法,必须要运行着 clash 才能用(开不开系统代理都可以)。

如果想取消,终端输入:

git config --global --unset http.proxy
git config --global --unset https.proxy

本机用了这个,WSL 里也还是不行的(好像本机只是转发 WSL 的包,我还不太清楚 WSL 网络与本机网络的关系)

而且 WSL 里没有 clash,也不太好再用第一种方法。

于是用第二种方法,改 host 文件

参考下面两篇做法:
https://blog.csdn.net/qq_41579104/article/details/107200570
https://blog.csdn.net/sky_jiangcheng/article/details/130982867

windows 改

linux 则是改 /etc/hosts

hosts 文件最后加上:

140.82.121.3 github.com
199.232.69.194 github.global.ssl.fastly.net

该方法即强行改变 DNS 缓存。

也不知道为什么 DNS 上的 github.com 总是被污染。

posted @ 2024-02-26 20:08  Cold_Chair  阅读(570)  评论(0编辑  收藏  举报