Basic Extraction
To extract a single directory and make it the root of your repository:Clone the repository
Start with a fresh clone of your repository:
git-filter-repo requires a fresh clone as a safety measure. Use
--force to override this requirement if absolutely necessary.Extract the subdirectory
Use the This will:
--subdirectory-filter option to extract a directory:- Keep only files under
src/ - Move
src/contents to the repository root - Remove commits that only touched files outside
src/
Extract and Rename to Subdirectory
For merging into another repository, you may want to extract a directory but place it under a new path:- Extracts only the
src/directory - Places it under
my-module/src/in the filtered repository - Preserves the full history
Advanced: Extract and Rename
Extract a specific subdirectory and rename it to a different path:src/some-folder/some-feature/ but renames it to src/.
Complete Example: Prepare for Merging
When preparing a subdirectory to merge into another repository:Extract and reorganize
- Extracts the
src/directory - Moves it to
my-module/src/ - Prefixes all tags with
my-module-to avoid conflicts
