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.
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 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