This version of GitHub Enterprise was discontinued on 2023-03-15. No patch releases will be made, even for critical security issues. For better performance, improved security, and new features, upgrade to the latest version of GitHub Enterprise. For help with the upgrade, contact GitHub Enterprise support.
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.
-
Open TerminalTerminalGit Bash.
-
Change the current working directory to the location where you want to create your new repository.
-
Clone the repository that contains the subfolder.
$ git clone https://HOSTNAME/USERNAME/REPOSITORY-NAME -
Change the current working directory to your cloned repository.
$ cd REPOSITORY-NAME -
To filter out the subfolder from the rest of the files in the repository, install
git-filter-repo, then rungit filter-repowith 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 > Rewrite 48dc599c80e20527ed902928085e7861e6b3cbe6 (89/89) > Ref 'refs/heads/BRANCH-NAME' was rewrittenThe repository should now only contain the files that were in your subfolder(s).
-
Create a new repository on GitHub Enterprise Server.
-
At the top of your new repository on your GitHub Enterprise Server instance's Quick Setup page, click to copy the remote repository URL.
Tip: For information on the difference between HTTPS and SSH URLs, see "About remote repositories."
-
Add a new remote name with the URL you copied for your repository. For example,
originorupstreamare two common choices.git remote add origin https://HOSTNAME/USERNAME/REPOSITORY-NAME.git -
Verify that the remote URL was added with your new repository name.
$ git remote -v # Verify new remote URL > origin https://HOSTNAME/USERNAME/NEW-REPOSITORY-NAME.git (fetch) > origin https://HOSTNAME/USERNAME/NEW-REPOSITORY-NAME.git (push) -
Push your changes to the new repository on GitHub Enterprise Server.
git push -u origin BRANCH-NAME
