備忘録:Gitリポジトリ分割手順

Gitリポジトリをサブフォルダごとに分割する手順

前提条件

  • OS: Windows(Git Bash使用)
  • git filter-repo インストール済み
  • 元リポジトリ: claude-project(ルート)
  • 分割対象フォルダ: PDF_Editor, bookkeeping_OCR, loto, numbers

Step 1: リポジトリをクローン

git clone https://github.com/yourname/claude-project.git
cd claude-project

Step 2: git filter-repo の確認

git filter-repo --version

Step 3: 元リポジトリのバックアップ

cd ~/work/project
cp -r claude-project claude-project_backup

Step 4: 各サブフォルダを独立したリポジトリに分割

# PDF_Editor
cp -r claude-project repo_PDF_Editor
cd repo_PDF_Editor
git filter-repo --subdirectory-filter PDF_Editor
cd ..

# bookkeeping_OCR
cp -r claude-project repo_bookkeeping_OCR
cd repo_bookkeeping_OCR
git filter-repo --subdirectory-filter bookkeeping_OCR
cd ..

# loto
cp -r claude-project repo_loto
cd repo_loto
git filter-repo --subdirectory-filter loto
cd ..

# numbers
cp -r claude-project repo_numbers
cd repo_numbers
git filter-repo --subdirectory-filter numbers
cd ..
⚠️ filter-repo 実行後は origin リモートが削除されるので git remote add が必要

Step 5: 各リポジトリをGitHubにpush

cd repo_PDF_Editor
git remote add origin https://github.com/yourname/PDF_Editor.git
git push -u origin master

bookkeeping_OCR, loto, numbers も同様に繰り返す

Step 6: 元リポジトリから分割済みフォルダを削除

cd ~/work/project/claude-project
git rm -r PDF_Editor bookkeeping_OCR loto numbers
git commit -m "Remove subfolders after repository split"
git push origin master

Step 7: 作業用コピーを削除

cd ~/work/project
rm -rf claude-project_backup
rm -rf repo_PDF_Editor repo_bookkeeping_OCR repo_loto repo_numbers

Step 8: 分割済みリポジトリをクローンし直す

cd ~/work/project
git clone https://github.com/yourname/PDF_Editor.git
git clone https://github.com/yourname/bookkeeping_OCR.git
git clone https://github.com/yourname/loto.git
git clone https://github.com/yourname/numbers.git

ポイント・注意事項

項目
内容
コミット履歴
各フォルダに関係する履歴のみ保持される
リモート確認
git remote -v
で現在の紐づけを確認できる
バックアップ
必ず取ること(履歴書き換えは不可逆)
filter-repo後
origin
リモートが削除される