LoginSignup
34
29

More than 5 years have passed since last update.

git で shallow clone

Last updated at Posted at 2014-05-17

git clone に時間がかかる場合、--depth を指定して浅く clone すると早い

通常

$ time git clone git@github.com:ruby/ruby.git
128.44s user 37.45s system 94% cpu 2:55.36 total

depth 指定

$ time git clone --depth=1 git@github.com:ruby/ruby.git
1.26s user 1.42s system 20% cpu 12.964 total

早い!

git log で見た時に commit log が depth で指定した数だけになっている。ローカルへの commit log をそれだけしか積まないので早くなるのだ。svn 的だ。

注意:ただし、このレポジトリから push はできなくなるので、用途は限定的だ。手元に素早く持ってきたいだけの場合に使う。Jenkins とか CI 環境で使うとよさそう。

branch

あとこれはおまけだけど、clone してから git checkout -b ブランチ名 origin/ブランチ名 で branch を切り替えるよりも、clone 時に --branch でブランチ名を指定しつつ、--single-branch オプションを使うと早い。

$ git clone --depth=1 --branch ruby_2_1 --single-branch git@github.com:ruby/ruby.git

みたいな。CI だと branch 指定するしね。

追記:良いエントリがあったのでリンク貼っておく。合わせて読みたい: 巨大なリポジトリを Git で上手く扱う方法

34
29
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
34
29