git-filter-repo
Quickly rewrite git repository history (filter-branch replacement)
git-filter-repo is now recommended by the git project instead of git filter-branch.
Why git-filter-repo?
Lightning Fast
Orders of magnitude faster than filter-branch for non-trivial repositories
Powerful Filtering
Path-based filtering, content replacement, commit message rewriting, and more
Safe by Design
Detects and requires fresh clones, automatic cleanup, intelligent safety checks
Library & CLI
Use as a command-line tool or Python library for custom filtering scripts
Key Features
- Fast repository history rewriting — Multiple orders of magnitude faster than filter-branch
- Path-based filtering — Keep or remove specific paths with simple flags
- File and directory renaming — Easily restructure your repository layout
- Repository analysis — Identify large files and directories before filtering
- Commit message rewriting — Update commit messages with new hashes automatically
- Tag renaming and filtering — Rename or filter tags during the rewrite
- Python library API — Write custom filtering scripts leveraging the core engine
- Automatic cleanup — Repository optimization and cleanup happens automatically
Use Cases
git-filter-repo excels at common repository maintenance tasks:Extract a subdirectory into its own repository
Extract a subdirectory into its own repository
Extract a portion of your repository while preserving history, perfect for splitting monorepos or creating focused repositories.
Remove sensitive data from history
Remove sensitive data from history
Permanently remove passwords, API keys, or other sensitive data that was accidentally committed.
Reorganize repository structure
Reorganize repository structure
Move files and directories around while maintaining full commit history.
Clean up large files
Clean up large files
Remove large files that are no longer needed to reduce repository size.
Rewrite commit messages
Rewrite commit messages
Update commit messages to reference new commit IDs after filtering.
How It Works
At its core, git-filter-repo works by running:Prerequisites
Before installing git-filter-repo, ensure you have:- Git >= 2.36.0
- Python >= 3.6
Quick Example
Here’s a simple example that extracts a subdirectory, moves it to a new location, and renames tags:- Keeps only files under
src/ - Moves everything into a new
my-module/directory - Prefixes all tags with
my-module-
This is just the beginning. git-filter-repo can handle much more complex filtering operations through its command-line options and Python API.
Next Steps
Installation
Install git-filter-repo on your system
Quickstart
Run your first filtering operation
Command Reference
Explore all command-line options
Examples
See common filtering patterns
