Git | 在clone时为github配置代理

平常clone的项目都是文本,今天遇到一个项目中单文件好几M,特别慢,所以找了一个配置代理的方法,亲测可用。

搬运自这里

设置ssh代理(终极解决方案)

https代理存在一个局限,那就是没有办法做身份验证,每次拉取私库或者推送代码时,都需要输入github的账号和密码,非常痛苦。

更进一步是设置ssh代理。只需要配置一个config就可以了。

1
2
3
4
5
# Linux、MacOS
vi ~/.ssh/config
# Windows
到C:\Users\your_user_name\.ssh目录下,新建一个config文件(无后缀名)

将下面内容加到config文件中即可

对于windows用户,注意代理会用到connect.exe,你如果安装了Git都会自带connect.exe,如我的路径为C:\APP\Git\mingw64\bin\connect

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#Windows用户,注意替换你的端口号和connect.exe的路径
ProxyCommand "C:\APP\Git\mingw64\bin\connect" -S 127.0.0.1:51837 -a none %h %p

#MacOS用户用下方这条命令,注意替换你的端口号
#ProxyCommand nc -v -x 127.0.0.1:51837 %h %p

Host github.com
User git
Port 22
Hostname github.com
# 注意修改路径为你的路径
IdentityFile "C:\Users\Your_User_Name\.ssh\id_rsa"
TCPKeepAlive yes

Host ssh.github.com
User git
Port 443
Hostname ssh.github.com
# 注意修改路径为你的路径
IdentityFile "C:\Users\Your_User_Name\.ssh\id_rsa"
TCPKeepAlive yes

保存后文件后测试方法,建议clone一个有大文件的项目,看看速度,同时也可以看看代理的流量。