git clone network speed is too slow, what to do, teach you how to solve

git clone network speed is too slow, what to do, teach you how to solve

How to speed up git clone

Do you often use git tools to clone repositories when doing code version management, especially github repositories in the open source market? I believe many IT personnel will use it. When using it, do you often encounter the situation where git clone ... the network is disconnected or cannot be connected? After all, github is a foreign thing, and you can't do anything about it. [Don't get angry at this time, getting angry is harmful to your health. ]

Today I’m going to share with you 5 very practical ways to speed up git clone.

Method 1: git clone (recommended method)

This is a more reliable method and is effective in the long run.

How to use: git clone https://gitclone/github.com/your repository address

For example:

The original git command is as follows. The entire git process may take 20 minutes.

 git clone https://github.com/pzl/oa1.git

If you change to the following method, the whole process may only take 1-2 minutes

 git clone https://gitclone.com/github.com/pzl/oa1.git

This can speed up the git clone process. Of course, there are other methods, such as modifying the hosts file, using a proxy, cloning the repository to a domestic repository, etc.

Method 2: Edit the Hosts file

Step 1: Resolve the IP address of github.com

 nslookup github.com

Step 2: Modify hosts

  • Hosts file path on Windows:
 C:\Windows\System32\drivers\etc\hosts
  • Hosts file path for Mac/Linux:
 sudo vim /etc/hosts

Add the IP address just resolved to the hosts file, hosts file format

 ... 102.121.1.* github.com ...

Method 3: Use a domestic mirror

When using git clone in China, the connection to GitHub may be slow due to network reasons. In this case, we can use domestic mirrors to speed up. Commonly used domestic mirrors include:

  • Code Cloud
  • Alibaba Cloud
  • Tencent Cloud

Using these domestic mirror sites can increase the speed of git clone. The specific steps are as follows:

  • Open the mirror site, register and log in to your account.
  • Create a new repository.
  • When using the git clone command locally, pass the repository address of the mirror site as a parameter.

Method 4: Refresh local DNS

Windows Flush DNS:

 ipconfig /flushdns

Linux flush DNS:

 systemctl restart nscd或者/etc/init.d/nscd restart

Mac flush DNS:

 sudo killall -HUP mDNSResponder

Method 5: Use a proxy

Proxy is a way of accessing external resources through an intermediary, which can usually speed up access to external networks. Similar to Taobao mirroring, Git Clone is often slow due to network problems. At this time, using a proxy can greatly increase the download speed.

Use the proxy setting command provided by Git official website:

 git config --global http.proxy http://127.0.0.1:1080

Among them, http://127.0.0.1:1080 is the proxy address and port number. After the setting is completed, all Git Clone operations will use the proxy to access, thereby increasing the download speed.

We have introduced the git clone acceleration method, and of course we will also review the most basic git usage methods.

How to use git

1. Initialize the warehouse

Create a new folder locally as a git repository, and then use the following command to initialize the repository:

 git init

2. Add files

Add the files that need version management to the git repository:

 git add 文件名

3. Commit changes

Commit the file changes to the git repository:

 git commit -m "提交说明"

4. Check the status

Check the status of the git repository to see how the files have changed:

 git status

5. View commit history

View the commit history of the git repository:

 git log

6. Switch branches

Create a new branch and switch to it:

 git checkout -b 分支名

7. Merge branches

Merge the contents of the specified branch into the current branch:

 git merge 分支名

8. Pull remote repository

Pull the latest code from the remote repository to the local:

 git pull 远程仓库地址

9. Push to remote repository

Push the local code to the remote repository:

 git push 远程仓库地址


<<:  Are wireless networks more energy efficient than wired LANs?

>>:  The network protocols behind server push, online gaming, and email

Recommend

LAN vs. WLAN: Connecting the Wired and Wireless Worlds

Local Area Networks (LANs) and Wireless Local Are...

JD.com's Lv Jianwei: Black technology leads the new era of e-commerce

[51CTO.com original article] On July 21-22, 2017,...

...

Picture | Someone finally explains 5G clearly...

The lives of our generation are changing so fast....

The difference between hybrid WAN and SD-WAN

The concepts of hybrid WAN and SD-WAN are often m...

Detailed explanation of STM32 network DMA controller

[[380257]] The block diagram of the STM32 network...

Risks and opportunities in the 5G era

At the end of 2018, the 5G frequency allocation o...