bashadvanced
Git Filter-Repo — Rewrite Entire History
Use git-filter-repo to remove secrets, rename authors, or extract subdirectories from Git history.
bashPress ⌘/Ctrl + Shift + C to copy
# Install git-filter-repo (pip or brew)
pip install git-filter-repo
# or: brew install git-filter-repo
# Remove a file from ALL history (e.g. leaked secret)
git filter-repo --path secrets.env --invert-paths
# Remove a directory from all history
git filter-repo --path-glob 'build/*' --invert-paths
# Remove files by pattern
git filter-repo --path-regex '.*\.log$' --invert-paths
# Replace text in all files across history (e.g. API key)
git filter-repo --replace-text expressions.txt
# expressions.txt contains:
# sk-live-abc123==>***REDACTED***
# literal:password123==>***REDACTED***
# Change author/committer email
git filter-repo --email-callback '
return email.replace(b"old@company.com", b"new@company.com")
'
# Extract a subdirectory into its own repo
git filter-repo --subdirectory-filter packages/shared
# Now the root IS packages/shared, history preserved
# Analyze repo (find large blobs, etc.)
git filter-repo --analyze
cat .git/filter-repo/analysis/blob-shas-and-paths.txt
# After filter-repo, force push to remote:
git push origin --force --all
git push origin --force --tagsSponsored
GitHub Copilot
Use Cases
- Removing accidentally committed secrets from history
- Extracting subdirectories into standalone repos
- Migrating email addresses after company changes
Tags
Related Snippets
Similar patterns you can reuse in the same workflow.
bashintermediate
Squash Multiple Git Commits
Interactive rebase to squash multiple commits into one clean commit before merging a feature branch.
Best for: Cleaning up messy commit history
#git#squash
bashbeginner
Delete Remote Git Branch
Commands to delete local and remote branches, prune stale references, and clean up merged branches.
Best for: Cleaning up after merged pull requests
#git#branch
bashadvanced
Git Interactive Rebase Guide
Interactive rebase to reorder, edit, drop, and squash commits for a clean Git history.
Best for: Crafting a clean commit history before merge
#git#rebase
bashbeginner
Git Log Formatting Tricks
Custom git log formats with graphs, filtering by author, date ranges, and file changes.
Best for: Reviewing project history efficiently
#git#log