LoginSignup
1
1

More than 3 years have passed since last update.

GitのSubmoduleを構成するファイルについて

Last updated at Posted at 2020-05-12

はじめに

リポジトリが分かれている場合、それをまとめるリポジトリがあると便利です。

事前に

追加したいサブモジュールが空の場合にはエラーとなるので、対象のリポジトリをクローンして何かコミットしておくと良いです。

$ touch README.md
$ git add README.md; git commit -m 'first commit'; git push origin HEAD

Submodule add

サブモジュールの追加は git submodule add で行ないます。

$ git submodule add git@github.com:yousan/example.git example

うまく行かない場合がありますが、その場合には手動で確認を行ないます。

サブモジュールは3つのファイルによって構成されているようです。

ファイル名
/.gitmodules
.git/config
(サブモジュールを置くディレクトリ)/.git

.gitmodule

サブモジュールに関する記述があります。

.gitmodule
[submodule "example"]
        path = example
        url = git@github.com:yousan/example.git

.git/config

.git/config
[submodule "example"]
        url = git@github.com:yousan/example.git
        active = true

example/.git

サブモジュールのディレクトリには .git ディレクトリではなくファイルが置いてあります。

example/.git
gitdir: example

エラーが出た場合には

上記の3ファイルが揃っていればSourceTreeなどでSubmoduleとして認識されます。うまく認識されない場合には上記のファイルを確認することとなります。

1
1
1

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
1