13
12

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

git subtree 運用のススメ

Last updated at Posted at 2016-03-18

コマンドとか基本的な使い方は

にまとめました。

submodule と違って、subtreeは他のユーザに不便を書けること無く運用が回って非常に便利なのだけど
.submoduleみたいな設定定義ファイルが無いので、モジュール管理を行うオーナにとっては苦痛が多かったりする。

とりあえず個人的に今のところこういう形で回してイますというメモ書きを。

remote 管理

submoduleの配信先remoteは全てremote登録しておく。

subtreeコマンドを叩く際に 毎回URL引っ張ってくるのは流石に面倒

複数remoteからのfetch は git fetch --all で対応可能

subtreeの切り出し

個人的にはsubtreeの切り出しはローカルブランチで行いたいので remoteには.を指定している。
複数のsubtreeを一括してローカルブランチに切り出せる用のエイリアスコマンドを.git/configに記載しておくと便利感ある。

.git/config
[alias]
	subpush = \
	!git subtree push --prefix subtree/module_a/ . module_a && \
	 git subtree push --prefix subtree/module_b/ . module_b && \
	 git subtree push --prefix subtree/module_b/ . module_c

subtree の進行状況比較

git show-branch で進行状況を確認する。

前述のとおりfetch --allで全てのリモートを更新できるので、最新の状態を取得したら、
後はshow-branchで比較するだけ。

利用するリモートブランチに応じて若干記述は異なるが概ね以下の様なコマンドで確認できるはず

$ git show-branch module_a module_a/master 

ローカルブランチとリモート名を合わせておくと楽

あとは必要に応じてpullしたりpushしたり

更新のリモート反映

$ git push module_a module_a:master

更新の取り込み

$ git pull module_a master:module_a
$ git subtree pull --prefix=subtree/module_a . module_a
13
12
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
13
12

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?