How to split repository in Git
Splitting a monorepo into separate repositories is a common scaling decision when a codebase grows and different teams need independent release cycles.
As the creator of CoreUI with 25 years of open-source development experience, I split the CoreUI monorepo into framework-specific packages and preserved the commit history for each component, which was essential for tracking bug history and attribution.
The tool for this is git filter-repo, which can extract a subdirectory into a new repository with its full commit history.
The result is a standalone repository containing only the commits that touched the extracted directory.
Extract a subdirectory into a new standalone repository.
# Install git-filter-repo
pip install git-filter-repo
# Clone the original monorepo
git clone https://github.com/org/monorepo.git monorepo-clone
cd monorepo-clone
# Extract only the packages/ui-library directory
# --subdirectory-filter moves the subdirectory to the root
git filter-repo --subdirectory-filter packages/ui-library
# The repo now contains only commits that touched packages/ui-library
# and the directory is at the root (not under packages/ui-library)
git log --oneline | head -10
After running --subdirectory-filter, the specified subdirectory becomes the new root of the repository. All commits that never touched that directory are removed, and the path prefix is stripped from all file paths in the remaining commits.
Preserve Multiple Directories
Extract multiple folders into a single new repository.
git clone https://github.com/org/monorepo.git multi-package-repo
cd multi-package-repo
# Keep multiple directories (they remain at their original paths)
git filter-repo \
--path packages/components/ \
--path packages/styles/ \
--path packages/utils/
When using --path (without --subdirectory-filter), the specified paths are kept at their original locations and everything else is removed. Use this when you want to preserve the directory structure in the new repository.
Create the New Remote Repository and Push
# Create the new repository on GitHub first (via UI or CLI)
# Then add it as the remote and push
git remote add origin https://github.com/org/ui-library.git
git push -u origin main
# Push all branches and tags if needed
git push origin --all
git push origin --tags
After the split, the new repository is self-contained. The original monorepo is unchanged — you cloned it before running filter-repo.
Remove the Extracted Directory from the Original
After splitting, remove the directory from the monorepo.
cd ../monorepo-original
# Remove the extracted directory from the monorepo
git rm -r packages/ui-library/
git commit -m "chore: extract ui-library to separate repository"
git push
This is a normal commit that removes the directory going forward. The historical commits in the monorepo still reference the files — only future commits won’t include them.
Best Practice Note
After splitting, update CI/CD pipelines, dependency references, and documentation to point to the new repository. If other packages in the monorepo depend on the extracted package, publish it to npm or use your package registry so other packages can install it. For the reverse operation — combining repositories — see how to combine repositories in Git. When working with large monorepos, also consider keeping them together using tools like Nx or Turborepo that enable independent versioning without splitting.



