git のレポジトリのサブディレクトリをforkするには

元ネタはここから

www.slideshare.net

こういう一つのレポジトリに複数のアプリのコードが入っているとき特定のアプリのサブディレクトリのみを自分のレポジトリにコピーしたくなったのでやってみた。

github.com

git clone git@github.com:googlesamples/android-architecture-components.git
cd android-architecture-components/
git filter-branch --force --subdirectory-filter PersistenceMigrationsSample HEAD
git remote add myrepo git@github.com:hoge/PersistenceMigrationsSample.git
git push myrepo