git clone コマンド
参考:
git-clone Documentation | Git [Official]
リポジトリの一部のみをクローンする (シャロークローン)
単一のブランチのみクローンする。
$ git clone --single-branch
指定したブランチのみクローンする。
$ git clone --branch master --single-branch
指定したコミット数だけクローンする。
$ git clone --depth 100
指定したブランチの指定したコミット数だけクローンする。
$ git clone --branch develop --depth 100
指定したタグのコミットのみクローンする。
$ git clone \ https://github.com/user_name/repo_name.git \ --branch v1.2.3 --depth 1
参考:
Git で容量が大きなリポジトリの一部だけダウンロードする方法 | gotohayato
巨大なリポジトリ を Git で上手く扱う方法 | Atlassian Blogs
とにかく速く特定のブランチを git clone したい場合の Tips – Qiita
git でリモートリポジトリを clone する際、特定のブランチだけ取ってきたい | oogatta のブログ
Git で特定のブランチ or タグを clone する – Qiita
ブランチ、タグを指定して git clone する|DIGITAL SQUAD ブログ
How do I clone a single branch in Git? – Stack Overflow
How to git clone a specific tag – Stack Overflow
Download a specific tag with Git – Stack Overflow
シャロークローンしたリポジトリに追加でフェッチする
.git/config
を開いて編集する。fetch
の行を追加する。
[remote "origin"] url = https://github.com:user/repo.git fetch = +refs/heads/master:refs/remotes/origin/master fetch = +refs/heads/develop:refs/remotes/origin/develop
全てのブランチを追跡する通常のクローンに戻したい場合は、ブランチ名の箇所にワイルドカードを指定する。
[remote "origin"] url = https://github.com:user/repo.git fetch = +refs/heads/*:refs/remotes/origin/*
参考:
git で single-branch を使用した後に別ブランチを fetch する方法 – Qiita
Refspec | Pro Git Book [Official]
シャロークローンしたリポジトリを履歴の新しいブランチとしてプッシュする
シャロークローンする。
$ git clone https://github.com/other/repo.git --branch v1.2.3 --depth 1
プッシュ先のリポジトリを origin
として設定する。
$ git remote set-url origin git@github.com:user/repo.git
履歴のない master
ブランチを作成する。
$ git checkout --orphan master
コミットする。
$ git commit -m 'v1.2.3'
origin
に master
をプッシュする。
$ git push -u origin master
参考:
Git で別の Repository に push するときに今までの commit 履歴を残さない方法 | grep Tips *
grafted
シャロークローン時にその先のコミットがフェッチされていない末端のコミットを指し示す。
参考:
grafted な git コミットとは何者か・・・ | つかろぐ
What exactly is a “grafted” commit in a shallow clone? – Stack Overflow