How to Solve The Problem of git clone From GitHub Very Slow
Solution 1: Setting Proxy
First, use a US proxy instead of others, like HK.
Setting HTTP Proxy for git clone by HTTPS URL
setting HTTP proxy for git
git config --global http.proxy socks5h://127.0.0.1:1080 |
or temporarily setting HTTP proxy for your terminal
// linux |
Test Case
Before Setting Proxy: about 200 KiB/s.
git clone https://github.com/mybatis/mybatis-3.git mybatis-clone-test |
After Setting Proxy: about 3 MiB/s.
git clone https://github.com/mybatis/mybatis-3.git mybatis-clone-test |
Proxy types
Use VPN client: {your_protocol}://127.0.0.1:{your_port}. for example, use client socks proxy
socks5h://127.0.0.1:1080
.Use HTTP proxy server: address:port. For example: http://proxyuser:proxypwd@proxy.server.com:8080
or Setting SSH Proxy for git clone by SSH URL
On Windows, add the following content to your git SSH config file ~/.ssh/config
:
ProxyCommand "C:\Program Files\Git\mingw64\bin\connect.exe" -S 127.0.0.1:1080 %h %p |
You can put the ProxyCommand ...
under a specific Host xxx.xxx.xxx
like this if you need to access multiple git hosting sites but set an SSH proxy for only one site.
Host ssh.github.com |
Git SSH config file path
- Windows:
- per user SSH configuration file:
~/.ssh/config
- system SSH configuration file:
C:\ProgramData\ssh\ssh_config
- per user SSH configuration file:
- Linux:
- per user SSH configuration file:
~/.ssh/config
- system SSH configuration file:
/etc/ssh/ssh_config
- per user SSH configuration file:
Git connect program
- Windows: {git_install_path}\Git\mingw64\bin\connect.exe (You can get the file path by running the command line
where connect.exe
) - Linux: /usr/bin/nc (You can get the file path by running the command line
whereis nc
)
Solution 2: Switching from using SSH to HTTPS
Using SSH: about 20 KiB/s
git clone git@github.com:xxx/xxx.git |
Using HTTPS: about 400 KiB/s
git clone https://github.com/xxx/xxx.git |
Other Improvements
git config --global http.postbuffer 524288000 |
References
[1] GitHub 加速终极教程
[2] SSH in git behind proxy on windows 7
[4] nc - OpenBSD