You can turn a folder within a Git repository into a brand new repository.
When splitting a folder into a separate repository, you won't lose any of your Git history or changes.
- Open Terminal (for Mac and Linux users) or the command line (for Windows users).
- Change the current working directory to your local project.
-
Run
git filter-branch
, making sure to include the name of the folder you want to separate.git filter-branch --prune-empty --subdirectory-filter \ YOUR_FOLDER_NAME master # Filter the master branch to your directory and remove empty commits # Rewrite 48dc599c80e20527ed902928085e7861e6b3cbe6 (89/89) # Ref 'refs/heads/master' was rewritten
-
The repository now contains all the files that were in your subfolder. Note that although all of your previous files have been removed, they still exist within the Git history. You can choose to push your repository to a new remote, or act upon them in any other way you would normally.
git push my-new-repo -f .