LoginSignup
1
0

More than 1 year has passed since last update.

git submoduleを使うときの私的メモ

Posted at

git submoduleを使おうと調べたときに,古い情報が混ざっていて困ったので,備忘録的に整理.

git submoduleの解説

他のgitリポジトリを参照する方法の一つ.自身のリポジトリで,サブディレクトリとして他のgitリポジトリを扱えるようにする.追加されたgitリポジトリをサブモジュールと呼ぶ.

リポジトリとは言っているが,特定のコミットを指している.大元のリポジトリが更新されても,自動的に追従はしてくれない.

他のgitリポジトリの追加

git submodule add 参照したいリポジトリのURL

サブモジュールを含むリポジトリのクローン

git clone --recursive リポジトリのURL

更新の追従

サブモジュールを更新する.

git submodule update --remote 

更新時に変更をマージする場合には

git submodule update --remote --merge

を実行する.

このとき,サブモジュールは特定のコミットを指した状態のままなので,サブモジュールのディレクトリ(名前はサブモジュールと同じ)に移動してmainブランチに切り替える.

cd サブモジュール名
git switch main

リポジトリのルートに戻り,サブモジュールの変更をマージする.

cd ..
git add サブモジュール名
git commit -m "コミットメッセージ"

GitHubで管理している場合はpushする

git push origin main
1
0
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
1
0