GitHub 访问慢?手把手教你几招解决它!,


由于众所周知的原因,在国内的网络环境下,访问 Github 时,网络会阻断或者很慢。本文提供了若干访问方法。

1 使用 Github Mirror 下载

直接在 GitHub 仓库前面拼接 Proxy 地址,不同的 Mirror 拼接方式可能有所不同。下面以拉取 https://github.com/shaowenchen/scripts 仓库为例。

  •  https://mirror.ghproxy.com 
  1. $ git clone https://mirror.ghproxy.com/https://github.com/shaowenchen/scripts 
  •  https://github.com.cnpmjs.org 
  1. $ git clone https://github.com.cnpmjs.org/shaowenchen/scripts  

2 通过 Gitee 导入 GitHub 项目

可以参考文档: GitHub仓库快速导入Gitee及同步更新, 将 GitHub 仓库导入 Gitee。然后使用 Gitee 的地址拉取代码。

文档链接:https://gitee.com/help/articles/4284

3 配置 Github Host 地址

打开 https://www.ipaddress.com/ 查询 github.com 的 IP 地址

编辑本地 /etc/hosts 文件,添加如下内容:

  1. 140.82.112.4 github.com 

或者直接使用开源项目 GitHub520 获取最新的 IP 地址。

项目地址:https://github.com/521xueweihan/GitHub520

接着就可以拉取代码了,但是速度并不会很快,因为 Github 用的是美国 IP。

4 配置命令行代理

如果有可用的代理服务,那么在本地 Terminal 中配置代理即可。

  1. # Proxy  
  2. function proxy_off(){  
  3.     unset http_proxy  
  4.     unset HTTP_PROXY  
  5.     unset https_proxy  
  6.     unset HTTPS_PROXY  
  7.     echo -e "已关闭代理"  
  8. }  
  9. function proxy_on(){  
  10.     export http_proxy="http://127.0.0.1:1087";  
  11.     export HTTP_PROXY="http://127.0.0.1:1087";  
  12.     export https_proxy="http://127.0.0.1:1087";  
  13.     export HTTPS_PROXY="http://127.0.0.1:1087";  
  14.     echo -e "已开启代理"  

本文转载自:「陈少文的网站」,原文:https://tinyurl.com/4tubycn9 ,版权归原作者所有。欢迎投稿,投稿邮箱: editor@hi-linux.com。

相关内容