Rewrite git history using git-filter-repo (not filter-branch)
Rewrites git history using git-filter-repo to remove files, secrets, or restructure paths.
/plugin marketplace add cowwoc/claude-code-cat/plugin install cat@claude-code-catThis skill inherits all available tools. When active, it can use any tool Claude has access to.
Purpose: Safely rewrite git history using git-filter-repo, the modern replacement for
git filter-branch.
NEVER use git filter-branch. Git itself warns against it:
git-filter-branch has a glut of gotchas generating mangled history rewrites. Use git-filter-repo instead.
| Feature | git-filter-repo | git-filter-branch |
|---|---|---|
| Speed | 10-50x faster | Slow |
| Safety | Handles edge cases | Many gotchas |
| Maintenance | Actively maintained | Deprecated |
| Syntax | Simple, intuitive | Complex, error-prone |
pip install git-filter-repo
# or
pip install --break-system-packages git-filter-repo
ALWAYS follow this pattern:
# Fresh clone required
git clone --mirror <url> repo-filter
cd repo-filter
# Remove file
git filter-repo --path secrets.txt --invert-paths
# Verify
git log --all --oneline -- secrets.txt # Should return nothing
# Push (requires --force)
git push origin --force --all
git filter-repo --path vendor/ --invert-paths
# This removes the gitlink entry for a submodule
git filter-repo --path submodule-name --invert-paths
# Rename a file across all history
git filter-repo --path-rename old-name.txt:new-name.txt
# Move directory
git filter-repo --path-rename old-dir/:new-dir/
# Remove files larger than 10MB
git filter-repo --strip-blobs-bigger-than 10M
# Keep only src/ directory (remove everything else)
git filter-repo --path src/
# Replace text patterns
git filter-repo --replace-text expressions.txt
# Where expressions.txt contains:
# PASSWORD=secret123==>PASSWORD=REDACTED
# regex:api_key=\w+==>api_key=REDACTED
By default, git-filter-repo requires a fresh clone. To work on an existing repo:
# CAUTION: Only if you understand the implications
git filter-repo --force --path file-to-remove --invert-paths
git push --force-with-lease origin <branch>git log --all -- <path>git diff --stat <old-commit>..<new-head>If something goes wrong:
# If you have original remote
git fetch origin
git reset --hard origin/<branch>
# If you kept a backup branch
git reset --hard backup-before-filter
This skill should be used when the user asks to "create a slash command", "add a command", "write a custom command", "define command arguments", "use command frontmatter", "organize commands", "create command with file references", "interactive command", "use AskUserQuestion in command", or needs guidance on slash command structure, YAML frontmatter fields, dynamic arguments, bash execution in commands, user interaction patterns, or command development best practices for Claude Code.
This skill should be used when the user asks to "create an agent", "add an agent", "write a subagent", "agent frontmatter", "when to use description", "agent examples", "agent tools", "agent colors", "autonomous agent", or needs guidance on agent structure, system prompts, triggering conditions, or agent development best practices for Claude Code plugins.
This skill should be used when the user asks to "create a hook", "add a PreToolUse/PostToolUse/Stop hook", "validate tool use", "implement prompt-based hooks", "use ${CLAUDE_PLUGIN_ROOT}", "set up event-driven automation", "block dangerous commands", or mentions hook events (PreToolUse, PostToolUse, Stop, SubagentStop, SessionStart, SessionEnd, UserPromptSubmit, PreCompact, Notification). Provides comprehensive guidance for creating and implementing Claude Code plugin hooks with focus on advanced prompt-based hooks API.