Open4
Git submodule備忘録(あるリポジトリから他のリポジトリを参照する仕組み)
![だーら(Flamers / Memotia)](https://res.cloudinary.com/zenn/image/fetch/s--K8Rv6qCG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_70/https://storage.googleapis.com/zenn-user-upload/avatar/eb6924b303.jpeg)
概要
- Gitリポジトリの中で、別のリポジトリを参照する仕組みであるGit submoduleについてのメモ
自分が使っているシーン
- iOS/Androidのネイティブプロジェクトが、Unityビルドを内包している(Unity as a Libraryという仕組み)
- Unity側のビルドをネイティブプロジェクトが取り込む。
参考
![だーら(Flamers / Memotia)](https://res.cloudinary.com/zenn/image/fetch/s--K8Rv6qCG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_70/https://storage.googleapis.com/zenn-user-upload/avatar/eb6924b303.jpeg)
サブモジュールを導入する
- 親となるリポジトリにてsubmodule addコマンド
git submodule add git@github.com:Org/RepositoryName.git
- すると自動で.gitmodulesファイルが生成され、中に以下のように記述されている。
[submodule "RepositoryName"]
path = RepositoryName
url = git@github.com:Org/RepositoryName.git
![だーら(Flamers / Memotia)](https://res.cloudinary.com/zenn/image/fetch/s--K8Rv6qCG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_70/https://storage.googleapis.com/zenn-user-upload/avatar/eb6924b303.jpeg)
サブモジュールを含んだリポジトリをclone
- 通常のcloneコマンドの末尾に
--recursive
をつける
git clone git@github.com:xxxx/yyyy.git --recursive
![だーら(Flamers / Memotia)](https://res.cloudinary.com/zenn/image/fetch/s--K8Rv6qCG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_70/https://storage.googleapis.com/zenn-user-upload/avatar/eb6924b303.jpeg)
サブモジュールのリポジトリの変更を取り込む
1. サブモジュールディレクトリに移動して、fetchとmerge
cd submodule-dir // サブモジュールのディレクトリに移動
- サブモジュールディレクトリで、
git fetch
git merge origin/main
2. 1の手順はディレクトリ移動があって煩雑なので、以下の1コマンドで出来る模様(未検証)
git submodule update --remote