git clone 时如何提高 git 协议的传输速度

2020 年 3 月 18 日
 yanyueio

从 github clone,如果走 git 协议一般会很慢,我这边一般会切换到 https 配置 git-credentials 和 access key,走 https 或者 socket5 代理,来提高速度,大概 500 KBi/s 的速度,so far so good.

但是这里需要单独生成 access key,且这个秘钥是暴露在文件中的。

所以想问大佬们,有没有人走 git 协议,去跑代理的?

any advice will be grateful.

6613 次点击
所在节点    程序员
31 条回复
unixeno
2020 年 3 月 18 日
git 就是走的 ssh,所以得在 ssh 配置里加代理
v2byy
2020 年 3 月 18 日
你说的是直接在 git config 中配置下 host 为 github 就走 http proxy ?需要单独生成 access key 吗
yuanfnadi
2020 年 3 月 18 日
```
Host *
UseKeychain yes
Host github.com
HostName github.com
User git
ProxyCommand nc -v -x 127.0.0.1:7891 %h %p
```

不谢
yanyueio
2020 年 3 月 18 日
.ssh 文件中配置的 config 文件中设置的 http 或者 https 代理也只是配置的 http/https 的代理,它无法针对 ssh/git 生效。

@v2byy access key 是因为我配置了 2fa,即 google authenticator 两步验证,所以直接走 https 的密码不行,必须在 github 上的 developer 项目里生成 access key 代替原来的 github 密码。
exiledkingcc
2020 年 3 月 18 日
我一般直接这样就行了:
export HTTPS_PROXY=....
git clone ......
yanyueio
2020 年 3 月 18 日
@yuanfnadi 您这个是针对 git clone ssh:// 生效的吧?

确定 github clone git@github.com 也行?
BrettD
2020 年 3 月 18 日
@exiledkingcc 这个只能代理 HTTPS 不能代理 SSH 协议吧?
run2
2020 年 3 月 18 日
@yuanfnadi #3 git config --global https.proxy 不香么?
yanyueio
2020 年 3 月 18 日
OK,刚刚试了一下,借助 nc 命令,是可以走到 socks5 代理的。

然后速度大致是直接用 https 的一般 275 KiB/s 左右。

@sobigfish 这里的关键是想实现的是免密,且不明文暴露密码。


结贴了,感谢以上各位的热心。

我的最终配置如下:


```bash
HOST github.com
UseKeychain yes
Host github.com
HostName github.com
IdentityFile /Users/yanyueio/.ssh/YanYueIO-PUB
port 22
User git
ProxyCommand nc -v -x 127.0.0.1:1086 %h %p

```

再次谢谢各位了。
yanyueio
2020 年 3 月 18 日
补充:

貌似速度和代理的拥塞程度有关,不一定是一半,有时候比直接用 https 的快。

remote: Enumerating objects: 1177, done.
remote: Counting objects: 100% (1177/1177), done.
remote: Compressing objects: 100% (205/205), done.
Receiving objects: 32% (602/1879), 134.14 MiB | 1.16 MiB/s
Tianao
2020 年 3 月 18 日
export all_proxy=socks5://[IP]:[port]
wuwukai007
2020 年 3 月 18 日
其实下载 zip 压缩包 并用迅雷下载超快的。
jinfeng333
2020 年 3 月 18 日
软路由 + 番茄上网
GitHub clone 一般 10M/s 峰值 20M/s

![]( https://wujunze.com/blog-images/r/pic/20200318124007.png)
jinfeng333
2020 年 3 月 18 日
@yanyueio #6 楼主 多少 M 带宽
CBS
2020 年 3 月 18 日
brzhang
2020 年 3 月 18 日
梯子
hshpy
2020 年 3 月 18 日
proxychains
ysc3839
2020 年 3 月 18 日
@yanyueio 你所说的 git@github.com 不是“git 协议”,是 SSH 协议的简写。
jinsongzhao
2020 年 3 月 18 日
@wuwukai007 不考虑自动更新代码吗?
bigmomo
2020 年 3 月 18 日
代理不行

[root@localhost ~]# git clone https://github.com/coolsnowwolf/lede.git
Cloning into 'lede'...
remote: Enumerating objects: 58485, done.
Receiving objects: 35% (20685/58485), 70.76 MiB | 4.82 MiB/s

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/653813

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX