{"meta":{"title":"サブフォルダを新規リポジトリに分割する","intro":"Git リポジトリ内のフォルダを、全く新しいリポジトリに変更できます。","product":"概要","breadcrumbs":[{"href":"/ja/enterprise-server@3.22/get-started","title":"概要"},{"href":"/ja/enterprise-server@3.22/get-started/using-git","title":"Git の使用"},{"href":"/ja/enterprise-server@3.22/get-started/using-git/splitting-a-subfolder-out-into-a-new-repository","title":"サブフォルダーの分割"}],"documentType":"article"},"body":"# サブフォルダを新規リポジトリに分割する\n\nGit リポジトリ内のフォルダを、全く新しいリポジトリに変更できます。\n\n> \\[!NOTE]\n> これらの手順に従うには Git バージョン 2.22.0 以降が必要です。それ以外の場合 `git filter-repo` は機能しません。\n\nリポジトリの新しいクローンを作成した場合でも、フォルダを別のリポジトリに分割したとき、Git の履歴や変更を失うことはありません。 ただし、元のリポジトリのブランチとタグは新しいリポジトリに含まれないことに注意してください。\n\n1. <span class=\"platform-mac\">\\[ターミナル]</span><span class=\"platform-linux\">\\[ターミナル]</span><span class=\"platform-windows\">\\[Git Bash]</span> を開きます。\n\n2. 現在のワーキングディレクトリを、新しいリポジトリを作成したい場所に変更します。\n\n3. サブフォルダのあるリポジトリをクローンします。\n\n   ```shell\n   git clone https://HOSTNAME/USERNAME/REPOSITORY-NAME\n   ```\n\n4. ワーキングディレクトリをクローンしたリポジトリに変更します。\n\n   ```shell\n   cd REPOSITORY-NAME\n   ```\n\n5. リポジトリ内の残りのファイルからサブフォルダーを除外するには、[`git-filter-repo`](https://github.com/newren/git-filter-repo) をインストールした後、次の引数を指定して `git filter-repo` を実行します。\n\n   * `FOLDER-NAME`: 別のリポジトリを作成するプロジェクト内のフォルダー。\n\n   <div class=\"ghd-tool windows\">\n\n   > \\[!TIP]\n   > Windowsユーザーは、`/` を使用してフォルダーを区切る必要があります。\n\n   </div>\n\n   ```shell\n   $ git filter-repo --path FOLDER-NAME/\n   # Filter the specified branch in your directory and remove empty commits\n   ```\n\n   これで、リポジトリにはサブフォルダー内にあったファイルだけが含まれるようになります。\n\n   特定のサブフォルダーを新しいリポジトリの新しいルート フォルダーにする場合は、次のコマンドを使用してください。\n\n   ```shell\n   $ git filter-repo --subdirectory-filter FOLDER-NAME\n   # Filter the specific branch by using a single sub-directory as the root for the new repository\n   ```\n\n6. GitHub に[新しいリポジトリを作成します](/ja/enterprise-server@3.22/repositories/creating-and-managing-repositories/creating-a-new-repository)。\n\n7. GitHub の \\[クイック セットアップ] ページにある新しいリポジトリの上部で、<svg version=\"1.1\" width=\"16\" height=\"16\" viewBox=\"0 0 16 16\" class=\"octicon octicon-copy\" aria-label=\"Copy to clipboard\" role=\"img\"><path d=\"M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 0 1 0 1.5h-1.5a.25.25 0 0 0-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 0 0 .25-.25v-1.5a.75.75 0 0 1 1.5 0v1.5A1.75 1.75 0 0 1 9.25 16h-7.5A1.75 1.75 0 0 1 0 14.25Z\"></path><path d=\"M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0 1 14.25 11h-7.5A1.75 1.75 0 0 1 5 9.25Zm1.75-.25a.25.25 0 0 0-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 0 0 .25-.25v-7.5a.25.25 0 0 0-.25-.25Z\"></path></svg> をクリックしてリモート リポジトリの URL をコピーします。\n\n   ![リポジトリ内の \\[クイック セットアップ\\] ヘッダーのスクリーンショット。 リモート URL の横にある 2 つの四角形が重なったアイコンがオレンジ色の枠線で囲まれています。](/assets/images/help/repository/copy-remote-repository-url-quick-setup.png)\n\n   > \\[!TIP]\n   > HTTPS と SSH の URL の違いについては、「[リモートリポジトリについて](/ja/enterprise-server@3.22/get-started/git-basics/about-remote-repositories)」を参照してください。\n\n8. コピーした自分のリポジトリ用の URL を使って新しいリモート名を追加します。 たとえば、`origin` や `upstream` の 2 つが一般的な選択肢です。\n\n   ```shell\n   git remote add origin https://HOSTNAME/USERNAME/REPOSITORY-NAME.git\n   ```\n\n9. 新しいリポジトリの名前を使い、リモート URL が追加されたことを確認します。\n\n   ```shell\n   $ git remote -v\n   # Verify new remote URL\n   > origin  https://HOSTNAME/USERNAME/NEW-REPOSITORY-NAME.git (fetch)\n   > origin  https://HOSTNAME/USERNAME/NEW-REPOSITORY-NAME.git (push)\n   ```\n\n10. 変更を GitHub の新しいリポジトリにプッシュします。\n\n    ```shell\n    git push -u origin BRANCH-NAME\n    ```"}