Gitで特定ブランチclone

git-hub01

 

--branch(または -b)オプションを使う

git clone --branch ブランチ名 リポジトリURL

 

例)develop ブランチをチェックアウトした状態でクローンされる。

これはリポジトリ全体を clone し、初期ブランチとして指定ブランチを checkout するという挙動。

git clone --branch develop https://github.com/example/repo.git

 

特定ブランチのみを shallow clone

履歴を最小限にして clone したい場合

git clone --branch ブランチ名 --single-branch リポジトリURL

特定のブランチを履歴ありで取得するので、リポジトリが大きい場合などに便利。

 

特定のブランチだけを clone

全履歴不要で最新の状態のみのClone。

git clone --depth 1 --branch ブランチ名 --single-branch リポジトリURL