notys's blog
大道至简
一招搞定GitHub开源项目下载加速 !

国内使用Github克隆项目时,实在是慢的一批,通常是 10KiB/s(爬墙除外),笔者的上一篇https://cherishspring.cn/archives/hostforgithub配置Host,但也是时好时坏,效果不明显。

正为这事发愁得我,正好一位知名B站Up主 解了我的愁,可以说是很多程序员的愁,先看看up主的视频吧 !

水文开始

一如既往地从github上克隆项目,速度还是一如既往的慢(10KiB/s以下)。

a

相信大家都有注册过码云,如下图,从GitHub/Gitlab导入仓库。

c

在从URL导入里填入我们的GitHub项目地址,速度非常快(不到一分钟)

d

e

使用gitee克隆项目,速度非常快

b

那么问题来了,既然是从码云拉取的项目,当然关联的是码云啦,那如果更新了代码,想再提交到github肿么办,需要将项目重新关联到github,且看下文 ~

$ git clone https://gitee.com/Notys/ssm.git
Cloning into 'ssm'...
remote: Enumerating objects: 321, done.
remote: Counting objects: 100% (321/321), done.
remote: Compressing objects: 100% (195/195), done.
remote: Total 321 (delta 69), reused 321 (delta 69)
Receiving objects: 100% (321/321), 12.07 MiB | 813.00 KiB/s, done.
Resolving deltas: 100% (69/69), done.

admin@DESKTOP-B73ETB7 MINGW64 /e/repo
$ pwd
/e/repo

admin@DESKTOP-B73ETB7 MINGW64 /e/repo
$ ls
ssm/

admin@DESKTOP-B73ETB7 MINGW64 /e/repo
$ cd ssm

admin@DESKTOP-B73ETB7 MINGW64 /e/repo/ssm (master)
$

使用ls -al命令查看该项目下的.git目录

admin@DESKTOP-B73ETB7 MINGW64 /e/repo/ssm (master)
$ ls -al
total 17
drwxr-xr-x 1 admin 197121    0  3月  9 10:10 ./
drwxr-xr-x 1 admin 197121    0  3月  9 10:10 ../
drwxr-xr-x 1 admin 197121    0  3月  9 10:10 .git/
-rw-r--r-- 1 admin 197121 1087  3月  9 10:10 LICENSE
-rw-r--r-- 1 admin 197121 4145  3月  9 10:10 pom.xml
-rw-r--r-- 1 admin 197121  460  3月  9 10:10 README.md
drwxr-xr-x 1 admin 197121    0  3月  9 10:10 src/

admin@DESKTOP-B73ETB7 MINGW64 /e/repo/ssm (master)
$

进入.git找到config配置文件

admin@DESKTOP-B73ETB7 MINGW64 /e/repo/ssm (master)
$ cd .git

admin@DESKTOP-B73ETB7 MINGW64 /e/repo/ssm/.git (GIT_DIR!)
$ ls
config       HEAD    index  logs/     packed-refs
description  hooks/  info/  objects/  refs/

admin@DESKTOP-B73ETB7 MINGW64 /e/repo/ssm/.git (GIT_DIR!)
$

vi命令打开config文件,可以看到url是gitee,将gitee改成github即可将项目重新关联到github啦 !

注意:

gitee个人空间地址要和github空间地址一致,否则可能出现以下问题:

$ git push
remote: Repository not found.
fatal: repository 'https://github.com/codesbull/ssm.git/' not found

这时需要将config中的url改成https://github.com/codesbull/ssm.git/即可。


admin@DESKTOP-B73ETB7 MINGW64 /e/repo/ssm/.git (GIT_DIR!)
$ vi config

[core]
        repositoryformatversion = 0
        filemode = false
        bare = false
        logallrefupdates = true
        ignorecase = true
[remote "origin"]
        url = https://gitee.com/Notys/ssm.git
        fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
        remote = origin
        merge = refs/heads/master

完成!

由于上面使用的是别人的github项目,下面使用本人自己的github+gitee再演示一遍

admin@DESKTOP-B73ETB7 MINGW64 /e/repo
$ git clone https://gitee.com/Notys/argon-theme.git
Cloning into 'argon-theme'...
remote: Enumerating objects: 941, done.
remote: Counting objects: 100% (941/941), done.
remote: Compressing objects: 100% (510/510), done.
remote: Total 941 (delta 405), reused 941 (delta 405)
Receiving objects: 100% (941/941), 6.68 MiB | 798.00 KiB/s, done.
Resolving deltas: 100% (405/405), done.

admin@DESKTOP-B73ETB7 MINGW64 /e/repo
$ ls
argon-theme/  ssm/

admin@DESKTOP-B73ETB7 MINGW64 /e/repo
$ cd argon-theme/

admin@DESKTOP-B73ETB7 MINGW64 /e/repo/argon-theme (master)
$ ls -al
total 777
drwxr-xr-x 1 admin 197121      0  3月  9 11:02 ./
drwxr-xr-x 1 admin 197121      0  3月  9 11:02 ../
drwxr-xr-x 1 admin 197121      0  3月  9 11:02 .git/
-rw-r--r-- 1 admin 197121     59  3月  9 11:02 .gitattributes
-rw-r--r-- 1 admin 197121     33  3月  9 11:02 .gitignore
-rw-r--r-- 1 admin 197121   2316  3月  9 11:02 404.php
-rw-r--r-- 1 admin 197121    995  3月  9 11:02 archive.php
-rw-r--r-- 1 admin 197121  24996  3月  9 11:02 argontheme.js
drwxr-xr-x 1 admin 197121      0  3月  9 11:02 assets/
-rw-r--r-- 1 admin 197121   5263  3月  9 11:02 comments.php
-rw-r--r-- 1 admin 197121    437  3月  9 11:02 comments-shuoshuo-preview.php
-rw-r--r-- 1 admin 197121   1314  3月  9 11:02 footer.php
-rw-r--r-- 1 admin 197121  69526  3月  9 11:02 functions.php
-rw-r--r-- 1 admin 197121  15228  3月  9 11:02 header.php
-rw-r--r-- 1 admin 197121    498  3月  9 11:02 index.php
-rw-r--r-- 1 admin 197121    208  3月  9 11:02 info.json
-rw-r--r-- 1 admin 197121  35823  3月  9 11:02 LICENSE
-rw-r--r-- 1 admin 197121    504  3月  9 11:02 page.php
-rw-r--r-- 1 admin 197121   6941  3月  9 11:02 README.md
-rw-r--r-- 1 admin 197121     30  3月  9 11:02 readme.txt
-rw-r--r-- 1 admin 197121 476003  3月  9 11:02 screenshot.png
-rw-r--r-- 1 admin 197121    961  3月  9 11:02 search.php
-rw-r--r-- 1 admin 197121    591  3月  9 11:02 searchform.php
-rw-r--r-- 1 admin 197121   1091  3月  9 11:02 shuoshuo.php
-rw-r--r-- 1 admin 197121  14744  3月  9 11:02 sidebar.php
-rw-r--r-- 1 admin 197121   1388  3月  9 11:02 single.php
-rw-r--r-- 1 admin 197121    514  3月  9 11:02 single-shuoshuo.php
-rw-r--r-- 1 admin 197121  78166  3月  9 11:02 style.css
drwxr-xr-x 1 admin 197121      0  3月  9 11:02 template-parts/
drwxr-xr-x 1 admin 197121      0  3月  9 11:02 theme-update-checker/

admin@DESKTOP-B73ETB7 MINGW64 /e/repo/argon-theme (master)
$ cd .git

admin@DESKTOP-B73ETB7 MINGW64 /e/repo/argon-theme/.git (GIT_DIR!)
$ ls
config       HEAD    index  logs/     packed-refs
description  hooks/  info/  objects/  refs/

由于我的github空间地址和gitee地址不一致,所以改成github空间地址

admin@DESKTOP-B73ETB7 MINGW64 /e/repo/argon-theme/.git (GIT_DIR!)
$ vi config

[core]
        repositoryformatversion = 0
        filemode = false
        bare = false
        logallrefupdates = true
        ignorecase = true
[remote "origin"]
        url = https://github.com/codesbull/ssm.git
        fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
        remote = origin
        merge = refs/heads/master

admin@DESKTOP-B73ETB7 MINGW64 /e/repo
$ ls
argon-theme/  ssm/

admin@DESKTOP-B73ETB7 MINGW64 /e/repo
$ cd argon-theme/

在此我修改了readme.txt文件

admin@DESKTOP-B73ETB7 MINGW64 /e/repo/argon-theme (master)
$ git status
Refresh index: 100% (453/453), done.
On branch master
Your branch is up to date with 'origin/master'.

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        modified:   readme.txt

no changes added to commit (use "git add" and/or "git commit -a")

admin@DESKTOP-B73ETB7 MINGW64 /e/repo/argon-theme (master)
$ git add readme.txt

admin@DESKTOP-B73ETB7 MINGW64 /e/repo/argon-theme (master)
$ git commit -m "修改readme,推送到github"
[master cf83ee8] 淇敼readme锛屾帹閫佸埌github
 1 file changed, 1 insertion(+), 1 deletion(-)

推送到github

admin@DESKTOP-B73ETB7 MINGW64 /e/repo/argon-theme (master)
$ git push
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Delta compression using up to 6 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 313 bytes | 313.00 KiB/s, done.
Total 3 (delta 1), reused 0 (delta 0)
remote: Resolving deltas: 100% (1/1), completed with 1 local object.
To https://github.com/codesbull/argon-theme.git
   303e7f1..cf83ee8  master -> master

admin@DESKTOP-B73ETB7 MINGW64 /e/repo/argon-theme (master)
$