The advent of Git and GitHub opens another door in the open source world, where versioning becomes more powerful (and more complex), project management becomes easier, and project development becomes easier to collaborate with people. GitHub is undoubtedly the programmer of Facebook, where there are countless world-class projects and top programmers, you can be interested in the project Asterisking (Star), you can focus on anyone (follow) and their projects (Watch), and, better yet, You can copy a copy of someone else's project (Fork) to make your own changes, and if you want, you can also initiate a request to the project's original author (pull request) and merge your changes into the original project. This will contribute to all open source projects, regardless of who you are, from different countries and with different skills.
Although the open source world described above is so beautiful, in the Big kingdom, in the wall, you are completely unable to appreciate. Because when you visit GitHub, or use angit cloneenthusiastic download of the items you are interested in, the slow speed will completely destroy your confidence, and eventually have to give up the show can't afford to play.
The powerful Great Wall technology for GitHub spared, not like Google or Facebook as a direct exterminate, but it has been strict speed limit, this torture than directly killed more painful (some netizens said that some regions are fast, some regions are very slow, may also be related to network operators ). As shown,git clonethe download speed has never exceeded 10kib/s, which means that a 100MiB project, it takes nearly three hours to finish, and due to network instability, the download process occasionally a disconnection situation, due togit clonenot support the continuation of the breakpoint, This allows a few hours of download time wasted, only to start again.
This article will cover several ways to quickly download code from GITHUB.
One, git shallow clone
git cloneThe full historical version of the project is downloaded by default, and if you care only about the latest version of the code and don't care about previous historical information, you can use Git's shallow copy feature:
$ git clone --depth=1 https://github.com/bcit-ci/CodeIgniter.git
--depth=1Indicates that only the most recent version is downloaded, using shallow copy can greatly reduce the amount of data downloaded, for example, the full download of the CodeIgniter project is nearly 100MiB, while the use of shallow copy only 5MiB more, so even in the harsh network environment, you can quickly get the code. If you later want to get complete history information, you can use the following command:
$ git fetch --unshallow
Or, if you just want to download the latest code look, you can also load the packaged ZIP file directly from GitHub, which is faster than shallow copy because it contains only the latest code files and is zip-compressed. But obviously, shallow copy is a little more flexible.
Second, GUI tools + Agent
If you're lucky enough to be using a proxy and know how to FQ, then visiting GitHub should be a cinch. The simplest way to download a project on GitHub is to use a graphical interface (GUI) Git tool that is now ubiquitous. The convenient place to use GUI tools is that you can configure whether you want to use a proxy in the settings, FQ the proxy IP you use for the configuration, or more directly, configure the agent as a system agent.
Third, Git + http.proxy
If you like me, prefer to use native git commands, like the feeling of operating under the command line, you can also configure Git to use the proxy directly under the command line, of course, you know how to FQ.
$ git config --global http.proxy http://proxyuser:[email protected]:8080
$ git config --global https.proxy https://proxyuser:[email protected]:8080
With the above command configured, a few more lines will be in the ~/.gitconfig file:
[http]
proxy = http://proxyuser:[email protected]:8080
[https]
proxy = https://proxyuser:[email protected]:8080
You can also use the following command to check if the configuration takes effect:
$ git config --global --get http.proxy
$ git config --global --get https.proxy
In addition, if you want to cancel this setting, you can:
$ git config --global --unset http.proxy
$ git config --global --unset https.proxy
After the configuration is complete, clone again, you can see the speed has been greatly improved!
Off-topic: How do I use proxies on the command line?
Note that using agit config --globalconfigured proxy can only be used by git programs, and if you want other commands on the command line to automatically use proxies, such as curl and wget, you can use the following method:
$ export http_proxy=http://proxyuser:[email protected]:8080
$ export https_proxy=https://proxyuser:[email protected]:8080
After the configuration is complete, HTTP and HTTPS requests from all command lines are automatically accessed through the proxy. If you want to cancel the proxy settings, you can:
$ unset http_proxy
$ unset https_proxy
It's also important to note that using Http_proxy and Https_proxy is only valid for HTTP and HTTPS requests, so it's no surprise when you ping www.google.com if the ping doesn't work.
Off topic: How do I use PAC files?
Sometimes we use git to access different git repositories, such as GitHub, or [email protected], or your own git server, but only when you want to access GitHub, use a proxy, access other warehouses, and don't use proxies. At this point we seem to be able to use PAC to solve this problem. The PAC (proxy autoconfiguration) is a technique used by browsers to automatically adopt different proxies based on different URLs, which contains aFindProxyForURLJavascript function that returns different proxies based on the URL.
Unfortunately, Git does not seem to support PAC files at the moment, but we can open the PAC file to find the address of the proxy, and then configure or cancel the configuration using the method above, just a bit cumbersome. Perhaps you can write a script to parse the PAC file, and the Git wrapper, to achieve automatic switching agent, there is a chance to try.
Iv. Other methods
There are a number of other methods available on the Web, but I have not tried it and recorded it:
- SSH tunnel or Shadowsocks
- SS + Proxychains
- Use of overseas VPS
- Powerpac
- Vpn
Reference
What if Git clone is too slow?