Frecuentemente publicamos actualizaciones de nuestra documentación. Es posible que la traducción de esta página esté en curso. Para conocer la información más actual, visita la documentación en inglés. Si existe un problema con las traducciones en esta página, por favor infórmanos.

Esta versión de GitHub Enterprise se discontinuará el 2021-06-09. No se realizarán lanzamientos de patch, ni siquiera para problemas de seguridad críticos. Para obtener un mejor desempeño, más seguridad y nuevas características, actualiza a la última versión de GitHub Enterprise. Para obtener ayuda con la actualización, contacta al soporte de GitHub Enterprise.

Splitting a subfolder out into a new repository

You can turn a folder within a Git repository into a brand new repository.

If you create a new clone of the repository, you won't lose any of your Git history or changes when you split a folder into a separate repository.

  1. Abre la TerminalTerminalGit Bash.

  2. Change the current working directory to the location where you want to create your new repository.

  3. Clone the repository that contains the subfolder.

    $ git clone https://nombre de host/USERNAME/REPOSITORY-NAME
  4. Change the current working directory to your cloned repository.

    $ cd REPOSITORY-NAME
  5. To filter out the subfolder from the rest of the files in the repository, run git filter-branch, supplying this information:

    • FOLDER-NAME: The folder within your project that you'd like to create a separate repository from.

      Tip: Windows users should use / to delimit folders.

    • BRANCH-NAME: The default branch for your current project, for example, main or gh-pages.

      $ git filter-branch --prune-empty --subdirectory-filter FOLDER-NAME BRANCH-NAME
        # Filter the specified branch in your directory and remove empty commits
        > Rewrite 48dc599c80e20527ed902928085e7861e6b3cbe6 (89/89)
        > Ref 'refs/heads/BRANCH-NAME' was rewritten

      The repository should now only contain the files that were in your subfolder.

  6. Create a new repository on GitHub Enterprise.

  7. At the top of your new GitHub Enterprise repository's Quick Setup page, click to copy the remote repository URL. Copy remote repository URL field

    Tip: For information on the difference between HTTPS and SSH URLs, see "About remote repositories."

  8. Check the existing remote name for your repository. For example, origin or upstream are two common choices.

    $ git remote -v
    > origin  https://nombre de host/USERNAME/REPOSITORY-NAME.git (fetch)
    > origin  https://nombre de host/USERNAME/REPOSITORY-NAME.git (push)
  9. Set up a new remote URL for your new repository using the existing remote name and the remote repository URL you copied in step 7.

    git remote set-url origin https://nombre de host/USERNAME/NEW-REPOSITORY-NAME.git
  10. Verify that the remote URL has changed with your new repository name.

    $ git remote -v
    # Verify new remote URL
    > origin  https://nombre de host/USERNAME/NEW-REPOSITORY-NAME.git (fetch)
    > origin  https://nombre de host/USERNAME/NEW-REPOSITORY-NAME.git (push)
  11. Push your changes to the new repository on GitHub Enterprise.

    git push -u origin BRANCH-NAME

¿Te ayudó este documento?

Privacy policy

Help us make these docs great!

All GitHub docs are open source. See something that's wrong or unclear? Submit a pull request.

Make a contribution

O, learn how to contribute.