Git使用代理克隆仓库

Git使用代理克隆仓库

克隆GitHub大型仓库(几十M以上的项目)一直是我的一个痛点。由于众所周知的原因,克隆GitHub上的仓库的速率正常只有十几KB/s,按这个速度不知道要到猴年马月才能把代码克隆下来。

使用下面这个命令:

1
2
3
4
5
6
7
8
I git clone https://github.com/lolimay/engine.git --config "https.proxy=http://localhost:49804"
Cloning into 'engine'...
remote: Enumerating objects: 137, done.
remote: Counting objects: 100% (137/137), done.
remote: Compressing objects: 100% (116/116), done.
remote: Total 115399 (delta 45), reused 47 (delta 19), pack-reused 115262
Receiving objects: 100% (115399/115399), 71.42 MiB | 310.00 KiB/s, done.
Resolving deltas: 100% (87791/87791), done.

使用 --config "https.proxy=本地代理地址" 命令可以以几百K的速度克隆仓库,记住一定要是克隆的 https:// 协议开头的链接,git@ 开头的协议代理没用。

克隆下仓库后再重新设置 remote 地址,不然每次 push 上去的时候都得输 GitHub 账号密码:

1
2
cd engine
git remote set-url origin git@github.com:lolimay/engine.git