git submodule

git

書き方

git submodule update --init --recursive

別のリポジトリをコミット一つに固定して自分のリポジトリ内に置きます。普通にクローンするとフォルダーは空で、update --initが必要ですし、親が押さえているのはブランチではなくコミットです。

よく使うオプション

オプション意味
add <url> <path>pin another repository at a path
update --initfill in a submodule folder that a clone left empty
--recursivego into submodules of submodules
update --remotemove the pin to the tip of the tracked branch
statusthe commit each submodule sits at
deinit <path>unregister it
foreach <cmd>run a command in each one

git submodule update --init --recursive

the command that fills empty submodule folders after a clone

git submodule add https://github.com/x/lib.git vendor/lib

adds a dependency as a submodule

git submodule update --remote

updates the pinned commit to the branch tip

取り消しに何通りもあるのが混乱のもとです — ブランチの指す先を動かすのと、打ち消すコミットを積むのは別です。

読み方

  • 角括弧 [ ] は省いてよい部分です。
  • 三点 … は複数並べられるという意味です。
  • オプションは大文字小文字を区別します — -r と -R が別物のコマンドもあります。

よくある質問

Q. git submodule は何をしますか。

別のリポジトリをコミット一つに固定して自分のリポジトリ内に置きます。普通にクローンするとフォルダーは空で、update --initが必要ですし、親が押さえているのはブランチではなくコミットです。

Q. どう打ちますか。

git submodule update --init --recursive — 角括弧は省いてよい部分です。

Q. よく使うオプションはいくつですか。

ここにまとめたのは7個です。全部は man git にあります。このコマンドはgitの仲間です。

関連するコマンド

man ページ: man git-submodule