Member-only story
Retain Your Repository’s History with These Easy Steps!
Firstly, it is important to note that splitting a subfolder from a repository with its history can be a bit tricky and involves some manual steps. Therefore, it is recommended that you make a backup of your repository before proceeding.
Here are the steps to split a subfolder from a repository with its history:
Step 1: Create a new repository First, you need to create a new repository that will contain the split subfolder. You can create a new repository on your preferred platform, such as GitHub, GitLab or Bitbucket.
Step 2: Clone the existing repository Next, clone the existing repository that contains the subfolder you want to split. You can do this using the following command in your terminal:
git clone <repository-url>
Step 3: Create a new branch Create a new branch in your local repository using the following command:
git checkout -b <new-branch-name>
Step 4: Remove all files except for the subfolder you want to split In your new branch, remove all files from the repository except for the subfolder you want to split. You can do this using the following command:
git rm -r --cached . git add <subfolder>
This will remove all files from the repository except for the subfolder you want to split and stage the subfolder for the next commit.