LoginSignup
2
1

More than 3 years have passed since last update.

Gitサブモジュールを使って静的コンテンツをわけてみる

Last updated at Posted at 2020-10-21

Gitサブモジュール

Gitサブモジュールを使用するとあるGitリポジトリを別のGitリポジトリのサブディレクトリとして扱うことができます。
これからGitサブモジュールを使って静的コンテンツ用のGitリポジトリをサブディレクトリとして使ってみます。

メインGitリポジトリ

「git_main」の名でリポジトリを作って以下のHtmlだけをPushして置きます。
このリポジトリにはイメージ(test.png)が存在しません。

html
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<img src="./assets/images/test.png"/>
</body>
</html>

スクリーンショット 2020-10-22 7.40.03.png

静的ファイルがあるGitリポジトリ

「assets」の名でリポジトリを作って以下のHtmlだけをPushして置きます。
こちらのリポジトリにイメージ(test.png)が存在します。
スクリーンショット 2020-10-22 7.51.23.png

メインGitリポジトリに「静的ファイルがあるGitリポジトリ」を「Gitサブモジュール」で追加

$git submodule add https://github.com/xxxxx/assets.git

Gitサブモジュール実行前

スクリーンショット 2020-10-22 7.52.53.png

Gitサブモジュール実行後

スクリーンショット 2020-10-22 7.53.15.png

.gitmodules

.gitmodulesファイルができて内容は以下のようなパスとURLが保存されます。

.gitmodules
[submodule "assets"]
    path = assets
    url = https://github.com/xxxxx/assets.git

assetsが更新された場合メインGitリポジトリから更新

  1. assetsリポジトリにイメージ(test2.png)をもう1つ追加してPUSH
  2. git_mainリポジトリから以下のコマンドを実行
  3. git_mainリポジトリにassetsリポジトリで追加したイメージが追加される。
$git submodule update --remote 

スクリーンショット 2020-10-22 8.05.17.png

2
1
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
2
1