git filter-branch who want to migrate to git-filter-repo. We’ll show you how to convert your existing commands and take advantage of filter-repo’s improved performance and safety.
Quick Reference
filter-branch and filter-repo have different approaches:- filter-branch: Checks out each commit and runs shell commands on the working copy
- filter-repo: Operates on the fast-export stream with predefined filters and Python callbacks
filter-repo defaults to rewriting all branches while filter-branch requires
-- --all to do so. Use --refs <rev-list-args> to limit the scope in filter-repo.Half-Hearted Conversions
You can quickly convert anygit filter-branch command by replacing it with filter-lamely:
- filter-branch
- filter-lamely
Basic Differences
Default Scope
- filter-branch: Operates on specified branches only (requires
-- --allfor everything) - filter-repo: Rewrites all refs by default (use
--refsto limit scope)
Automatic Improvements
filter-repo automatically handles:- Rewriting old commit IDs in commit messages
- Pruning commits that become empty
- Running garbage collection after filtering
- Shrinking repository size
Command Conversions
Removing a File
The filter-branch manual shows three variations of removing a file:- filter-branch
- filter-repo
Extracting a Subdirectory
Move a subdirectory to the repository root:- filter-branch
- filter-repo
Moving Tree into Subdirectory
Place all files into a new subdirectory:- filter-branch
- filter-repo
Re-grafting History
Attach history to a different parent commit:- filter-branch
- filter-repo
--proceed is required because filter-repo errors if no filtering arguments are specified.Removing Commits by Author
- filter-branch
- filter-repo
Rewriting Commit Messages
Removing Text
Remove git-svn-id lines from commit messages:- filter-branch
- filter-repo
Adding Text
Add Acked-by lines to the last 10 commits:- filter-branch
- filter-repo
Changing Author/Committer Info
Update email addresses throughout history:- filter-branch
- filter-repo (mailmap)
- filter-repo (callback)
Both filter-repo methods also update tagger emails, which filter-branch doesn’t handle.
Restricting to a Range
Filter only specific commit ranges:- filter-branch
- filter-repo
Use
^C instead of --not C with filter-repo to avoid flag parsing issues.Advanced Conversions
Running Code Formatters
Apply a code formatter to all matching files in history:- filter-branch
- filter-repo (callback)
- filter-repo (lint-history)
Migration Tips
Performance
filter-repo is significantly faster than filter-branch, especially for large repositories:- No checkout overhead
- Operates on fast-export stream
- Efficient blob handling
Safety
filter-repo includes built-in safety features:- Refuses to run on repos with uncommitted changes
- Creates backups by default
- Validates operations before execution
Next Steps
- Test on a clone first: Always test migrations on a repository copy
- Review changes: Use
git logandgit diffto verify results - Update remotes: After successful migration, force-push to update remote repositories
- Inform collaborators: Everyone needs to re-clone after history rewriting
Need More Examples?
See the Examples for common filtering patterns and advanced use cases.
