You can turn a folder within a Git repository into a brand new repository.
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 original 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.
- Change the current working directory to your cloned repository.
- To filter out the subfolder from the rest of the files in the repository, install
git-filter-repo
, then rungit filter-repo
with the following arguments.
FOLDER-NAME
: The folder within your project where youâd like to create a separate repository.
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:
- Create a new repository on GitHub.
- At the top of your new repository on GitHubâs Quick Setup page, click to copy the remote repository URL.
8. Add a new remote name with the URL you copied for your repository. For example, origin
or upstream
are two common choices.
- Verify that the remote URL was added with your new repository name.
- Push your changes to the new repository on GitHub.