git clone
git
書き方
git clone [--depth <n>] [-b <branch>] <url> [<directory>]リモートのリポジトリを履歴ごと複製します。--depth 1で浅く取ると古いコミットや他のブランチが無く、後で--unshallowが必要になります。
よく使うオプション
| オプション | 意味 |
|---|---|
| --depth <n> | shallow copy with only the last n commits |
| -b <branch> | check out that branch instead of the default |
| --single-branch | fetch one branch only |
| --recurse-submodules | clone submodules at the same time |
| --filter=blob:none | partial clone: fetch file contents on demand |
| -o <name> | call the remote something other than origin |
例
git clone https://github.com/user/repo.gitcopies the repository into repo/ and names the remote origin
git clone --depth 1 https://github.com/user/repo.gitfast copy for CI with no old history
git clone -b dev --single-branch <url>checks out dev and fetches nothing else
取り消しに何通りもあるのが混乱のもとです — ブランチの指す先を動かすのと、打ち消すコミットを積むのは別です。
読み方
- 角括弧 [ ] は省いてよい部分です。
- 三点 … は複数並べられるという意味です。
- オプションは大文字小文字を区別します — -r と -R が別物のコマンドもあります。
よくある質問
Q. git clone は何をしますか。
リモートのリポジトリを履歴ごと複製します。--depth 1で浅く取ると古いコミットや他のブランチが無く、後で--unshallowが必要になります。
Q. どう打ちますか。
git clone [--depth <n>] [-b <branch>] <url> [<directory>] — 角括弧は省いてよい部分です。
Q. よく使うオプションはいくつですか。
ここにまとめたのは6個です。全部は man git にあります。このコマンドはgitの仲間です。
関連するコマンド
man ページ: man git-clone