Claude Skills Guide

Claude Code for Git Filter-Repo Workflow

Git filter-repo is a powerful tool for rewriting Git history, but it can be intimidating due to its complexity and the irreversible nature of history rewriting. This guide shows how Claude Code can help you safely navigate filter-repo workflows, generate correct commands, and avoid common pitfalls.

What is Git Filter-Repo?

Git filter-repo is the modern replacement for older tools like BFG Repo-Cleaner and git-filter-branch. It allows you to:

The tool is incredibly powerful but requires careful planning since it rewrites commit hashes, affecting every commit in your repository’s history.

Setting Up Filter-Repo with Claude Code

First, ensure you have filter-repo installed. Claude Code can help you verify this:

# Check if filter-repo is installed
pip install git-filter-repo

# Verify installation
git filter-repo --version

Before proceeding with any filter-repo operation, always create a backup of your repository. Claude Code can help you set up a safe working environment:

# Clone your repository to a backup location
git clone --mirror git@github.com:yourorg/yourrepo.git backup-repo.git

Using Claude Code to Plan Your Filter-Repo Operation

The most valuable way Claude Code assists with filter-repo workflows is in the planning phase. Before running any destructive commands, describe your goal to Claude and ask for a step-by-step plan.

For example, you might say: “I need to remove all files larger than 100MB from my repository history and I want to keep only the src and docs directories.”

Claude can then generate the appropriate filter-repo command:

# First, identify large files
git filter-repo --analyze

# Review the analysis in .git/filter-repo/analysis/

# Remove files over 100MB from history
git filter-repo --strip-blobs-bigger-than 100M

# Keep only src and docs directories
git filter-repo --path src --path docs --path-rewrite src: docs:

Automating Common Filter-Repo Tasks

Claude Code excels at generating precise filter-repo commands for specific scenarios. Here are common workflows:

Removing Sensitive Data

To remove API keys or credentials that were accidentally committed:

# Create a file listing patterns to match
echo "api_key=" > patterns.txt
echo "password:" >> patterns.txt
echo "AWS_SECRET" >> patterns.txt

# Use filter-repo with regex matching
git filter-repo --replace-text expressions.txt

Claude can help you create the patterns file safely, ensuring you don’t accidentally remove legitimate data.

Extracting a Subdirectory

To create a new repository from a subdirectory:

# Extract the 'frontend' subdirectory as root
git filter-repo --subdirectory-filter frontend

Path Rewriting

To rename directories across all commits:

# Change 'lib/' to 'library/' throughout history
git filter-repo --path-rewrite lib:library

Safe Practices with Claude Code Assistance

Filter-repo operations are destructive and cannot be undone. Claude Code helps you follow these safety practices:

  1. Always back up first - Create a mirror clone before any operation
  2. Test on a copy - Run your filter-repo command on a test repository first
  3. Use –dry-run - Filter-repo doesn’t support dry-run, so test with a small subset
  4. Update all clones - After pushing filtered history, all collaborators must re-clone

Claude can generate a checklist for your specific workflow:

# Checklist for safe filter-repo operation
# 1. Notify all collaborators
# 2. Create backup: git clone --mirror
# 3. Verify backup integrity
# 4. Perform filter-repo operation
# 5. Verify result looks correct
# 6. Force push: git push --force --all
# 7. Force push all branches: git push --force --mirror
# 8. Notify collaborators to re-clone

Handling Post-Filter Issues

After running filter-repo, you may encounter common issues that Claude Code can help troubleshoot:

Detached HEAD or Missing Branches

# Check current branch state
git status
git branch -a

# Recreate main branch if needed
git checkout -b main

Large Object References

If you see warnings about reachable objects:

# Run garbage collection to clean up
git reflog expire --expire=now --all
git gc --prune=now --aggressive

Push Rejection

Force pushing may be rejected by branch protection rules:

# Temporarily disable branch protection
# Then force push
git push --force --all
git push --force --tags

Integrating Filter-Repo into Your Development Workflow

For ongoing repository maintenance, consider these Claude Code enhanced practices:

Conclusion

Git filter-repo combined with Claude Code provides a powerful workflow for repository maintenance. Claude acts as your assistant—generating correct commands, helping you plan complex operations, and troubleshooting issues that arise. Start with small, safe operations and gradually tackle more complex history rewrites as you gain confidence.

Remember: the key to successful filter-repo use is careful planning, thorough backups, and methodical execution. Let Claude Code help you every step of the way.

Built by theluckystrike — More at zovo.one