35
27

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

[Git] とにかく速く特定のブランチをgit cloneしたい場合のTips

Last updated at Posted at 2015-05-08

Vim の自動ビルドスクリプトを書いていたんですが、vim の clone が遅すぎるので対策を調べました

TL;DR

Gitのshallow cloneの機能を使いましょう。

-b branchname --single-branch --depth=1 とやればよさそう

検証

普通にgit cloneした場合

$ time git clone https://github.com/vim-jp/vim.git vim0

Cloning into 'vim0'...
remote: Counting objects: 56064, done.
remote: Compressing objects: 100% (131/131), done.
remote: Total 56064 (delta 76), reused 0 (delta 0), pack-reused 55933
Receiving objects: 100% (56064/56064), 157.80 MiB | 333.00 KiB/s, done.
Resolving deltas: 100% (35750/35750), done.
Checking connectivity... done.

real    8m12.556s
user    0m29.880s
sys     0m42.800s

ネット環境の影響もあるが遅い・・・

-b master --single-branch を使用する

$ time git clone -b master --single-branch https://github.com/vim-jp/vim.git vim1

Cloning into 'vim1'...
remote: Counting objects: 56063, done.
remote: Compressing objects: 100% (131/131), done.
remote: Total 56063 (delta 76), reused 0 (delta 0), pack-reused 55932
Receiving objects: 100% (56063/56063), 157.80 MiB | 325.00 KiB/s, done.
Resolving deltas: 100% (35750/35750), done.
Checking connectivity... done.

real    8m24.252s
user    0m31.904s
sys     0m43.812s

オブジェクト数は1減っているものの、時間は通信速度の影響下むしろ増加
ある程度歴史のあるリポジトリで、プランチが多く生存してる場合は効果がありそう。

--depth=1 を使用する

$ time git clone --depth=1 https://github.com/vim-jp/vim.git vim2

Cloning into 'vim2'...
remote: Counting objects: 2663, done.
remote: Compressing objects: 100% (2548/2548), done.
remote: Total 2663 (delta 137), reused 1762 (delta 53), pack-reused 0
Receiving objects: 100% (2663/2663), 11.81 MiB | 319.00 KiB/s, done.
Resolving deltas: 100% (137/137), done.
Checking connectivity... done.

real    0m43.275s
user    0m2.500s
sys     0m3.020s

とても速い・・・!!

-b master --single-branch --depth=1 を使用する

$ time git clone -b master --single-branch --depth=1 https://github.com/vim-jp/vim.git vim3

Cloning into 'vim3'...
remote: Counting objects: 2663, done.
remote: Compressing objects: 100% (2548/2548), done.
Receiving objects: 100% (2663/2663), 11.81 MiB | 322.00 KiB/s, done.
remote: Total 2663 (delta 137), reused 1762 (delta 53), pack-reused 0
Resolving deltas: 100% (137/137), done.
Checking connectivity... done.

real    0m42.486s
user    0m2.956s
sys     0m2.808s

--depth=1とさほどかわらず

結論

-b branchname --single-branch --depth=1 とやればよさそう

git submodule の場合

以下のようにすれば良さそうです

$ git submodule update --init --depth=1

ちなみに

$ git clone --recursive --depth=1 https://github.com/davidhalter/jedi-vim.git

とした場合、submodule の方には--depth=1 が適用されませんでした (git v1.9.1)

追記(git 2.9 ~)

--shallow-submodules というオプションが追加されたようです。

$ git clone --recursive --depth=1 --shallow-submodules https://github.com/davidhalter/jedi-vim.git

追記(git 2.10 ~)

Git 2.10から以下のオプションが使えるようになったようです。(未検証)

$ git config -f .gitmodules submodule.<name>.shallow true

Git shallow submodules - Stack Overflow

関連

[Git] shallow cloneしたリポジトリを、あとで完全にfetchする - Qiita

35
27
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
35
27

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?