Please enable Javascript to view the contents

国内访问 GitHub 的若干方法

 ·  ☕ 1 分钟

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

1. 使用 Github Mirror 下载

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

1
git clone https://mirror.ghproxy.com/https://github.com/shaowenchen/ops

2. 通过 Gitee 导入 GitHub 项目

可以参考文档: GitHub仓库快速导入Gitee及同步更新, 将 GitHub 仓库导入 Gitee。

然后使用 Gitee 的地址拉取代码。

3. 配置 Github Host 地址

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

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

1
140.82.112.4 github.com

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

4. 配置命令行代理

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

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

微信公众号
作者
微信公众号