
したいこと
レポジトリ内のディレクトリを、それぞれ新しいレポジトリとして登録したい。
.
└── Thesis <--> git@github.com:user/Thesis.git
├── thesis
│ └── thesis.tex
└── presentation
├── handout.tex
└── slides.tex
例えば、これ (上) をこう (下) したい. <--> はローカルとリモートの対応関係を表す.
.
├── Presentation <--> git@github.com:user/Presentation.git
│ ├── handout.tex
│ └── slides.tex
└── Thesis <--> git@github.com:user/Thesis.git
└── thesis.tex
やりかた
「Git で複数のリポジトリをまとめたり、逆に切り出したりする」を参考にしました。
まずは、Thesis のクローンであるローカルリポジトリ Presentation を作成します。
% mkdir Presentation
% git clone Thesis Presentation
コマンド git filter-branch で、レポジトリの内容をディレクトリ /presentation の内容で置き換えます。
% cd Presentation
% git filter-branch --subdirectory-filter presentation HEAD
この時点でこんな感じです。
.
├── Presentation <--> Thesis
│ ├── handout.tex
│ └── slides.tex
└── Thesis <--> git@github.com:uesr/Thesis.git
├── presentation
│ ├── handout.tex
│ └── slides.tex
└── thesis
└── thesis.tex
レポジトリ Presentation のリモート URL を書き換えます。
% git remote set-url origin git@github.com:user/Presentation.git
% git push
Thesis についても同様にサブディレクトリ thesis でフィルタして置き換えます。
% cd ../Thesis
% git filter-branch --subdirectory-filter thesis HEAD
% git push -f
これで完了です。下のようになっているはずです。
.
├── Presentation <--> git@github.com:user/Presentation.git
│ ├── handout.tex
│ └── slides.tex
└── Thesis <--> git@github.com:user/Thesis.git
└── thesis.tex
お疲れ様でした。