LoginSignup
9
8

More than 5 years have passed since last update.

Git submoduleで開発する手順

Last updated at Posted at 2014-09-17

動作確認で親リポジトリが必要だけど親に影響を与えたくないので、親落としてサブモジュールだけを開発するまでの手順です。

構成(node.js)

今回はnode.jsをサンプルにしています

.
└── oya
    ├── app.js
    ├── package.json
    ├── routes
    │   └── index.js
    ├── src
    │   ├── common
    │   ├── submoduleA
    │   └── submoduleB
    │       └── README.md
    └── views

親取得

まずは親リポジトリをクローンしてきます

$ git clone oya.git

サブモジュール中身を確認

この状態ではまだサブモジュールが無い事を確認します。
サブモジュールは参照だけなので落ちてきてない

$ ls -a oya/src/submoduleB
.   ..
# まだなにもない

サブモジュール取得

$ cd oya
$ git submodule init
$ git submodule update

もう一度、サブモジュール中身を確認

今度はサブモジュールの中身があります!

$ ls -a oya/src/submoduleB
.       ..      .git        README.md

サブモジュールでブランチ作成

親に影響無くブランチができるのを確認します

$ cd oya/src/submoduleB
$ git branch -a
* master
  remotes/origin/master
$ git checkout -b develop_subB
$ git push origin develop_subB
$ git branch -a
* develop_subB
  master
  remotes/origin/develop_subB
  remotes/origin/master

親のgitリポジトリに影響ないか確認

サブモジュールのブランチは表示されません!

$ cd ../../
$ git branch -a
* master
  remotes/origin/master

まとめ

  • サブモジュールは初期化&更新が必要
  • サブモジュールのディレクトリ以下の影響は親には伝わらない

気になる事

  • 親に変更入れた時に親でコミット忘れそう(ルーティング設定とか)
  • .gitmodulesの変更でブランチ指定とかし始めたら混乱しそう
  • 今回は担当が分かれているので親に影響が無い方がよいが運用フェーズになって横断的に修正が必要になる事が多そうならsubtreeを検討してみたい
9
8
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
9
8