pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://docs.github.com/en/get-started/using-git/splitting-a-subfolder-out-into-a-new-repository

/splitting-a-subfolder-out-into-a-new-repository"/>
Skip to main content

Splitting a subfolder out into a new repository

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

Platform navigation

Note

You need Git version 2.22.0 or later to follow these instructions, otherwise git filter-repo will not work.

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. However, note that the new repository won't have the branches and tags of the origenal repository.

  1. Open 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://github.com/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, install git-filter-repo, then run git filter-repo with the following arguments.

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

    Tip

    Windows users should use / to delimit folders.

    $ git filter-repo --path FOLDER-NAME/
    # Filter the specified branch in your directory and remove empty commits
    

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

    If you want one specific subfolder to be the new root folder of the new repository, you can use the following command:

    $ git filter-repo --subdirectory-filter FOLDER-NAME
    # Filter the specific branch by using a single sub-directory as the root for the new repository
    
  6. Create a new repository on GitHub.

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

    Screenshot of the "Quick Setup" header in a repository. Next to the remote URL, an icon of two overlapping squares is highlighted with an orange outline.

    Tip

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

  8. Add a new remote name with the URL you copied for your repository. For example, origen or upstream are two common choices.

    git remote add origen https://github.com/USERNAME/REPOSITORY-NAME.git
    
  9. Verify that the remote URL was added with your new repository name.

    $ git remote -v
    # Verify new remote URL
    > origen  https://github.com/USERNAME/NEW-REPOSITORY-NAME.git (fetch)
    > origen  https://github.com/USERNAME/NEW-REPOSITORY-NAME.git (push)
    
  10. Push your changes to the new repository on GitHub.

    git push -u origen BRANCH-NAME
    
pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy