git detach subfolder to their own repository If you create a new clone of a repository, you can split the folder into another repository without losing your Git
If you create a new clone of a repository, you can split the folder into another repository without losing your Git history or changes.
Open Git Bash.
Change your current working directory to where you want to create the new repository. 3. Clone the repository including subfolders.
$ git clone https://github.com/USERNAME/REPOSITORY-NAME
- Change your current working directory to the cloned repository.
$ cd REPOSITORY-NAME
Five. To filter subfolders from the rest of the files in the repository, use 'git-filter-repo', run git filter-repo with the following arguments:
- "Folder name":
A folder within a project in which to create another repository.
Up: Windows users must use "/" to separate 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 rewritten
Now the repository will only contain the files that were in the subfolders.
Create a new repository on GitHub.
At the top of your new repository, click the GitHub.com Quick Setup page.
Copy the remote repository URL.
Up: See About remote repositories.
- Add a new remote name using the URL you copied for your repository. For example, Origin or Upstream are two common choices.
git remote add origin https://github.com/USERNAME/REPOSITORY-NAME.git
- Make sure the remote URL is added with the new repository name.
$ git remote -v
# Verify new remote URL
> origin https://github.com/USERNAME/NEW-REPOSITORY-NAME.git (fetch)
> origin https://github.com/USERNAME/NEW-REPOSITORY-NAME.git (push)
- Push your changes to your new repository on GitHub.
git push -u origin BRANCH-NAME