Skip to main content

Overview

Content-based filtering allows you to modify file contents, remove large files, or replace sensitive data across your entire repository history. This is essential for cleaning up committed secrets, fixing typos, or removing unwanted content.

Text Replacement

Replace Sensitive Data

Remove passwords, tokens, or other sensitive text from history:
Security NoteAfter removing sensitive data, you MUST:
  1. Rotate/revoke the exposed credentials
  2. Force push to all remotes
  3. Ensure all team members reclone
See Sensitive Data Removal below.

Replacement Syntax

The expressions file supports multiple formats:
Default ReplacementIf ==> is not specified, the default replacement is ***REMOVED***.

Regex Features

Python regex syntax is supported:
See Python regex documentation for full syntax.

Stripping Large Files

By Size Threshold

Remove all files larger than a specific size:
Find Large Files FirstUse --analyze to identify large files:

By Blob ID

Remove specific files by their git object hash:
Format of blob ID file:

Modifying File Contents

Using Blob Callback

Modify file contents programmatically:
Binary DetectionCheck for null bytes in first 8KB to detect binary files:

Using File Info Callback

Filter based on filename, mode, and contents:

Apply Replace Text Selectively

Use --replace-text with --file-info-callback for selective replacement:
When using --file-info-callback, --replace-text replacements are NOT automatically applied. You must call value.apply_replace_text() explicitly.

Performance Optimization

Cache Transformations

Avoid reprocessing the same blob multiple times:

Sensitive Data Removal

For removing sensitive data (passwords, API keys, etc.):

Step 1: Prepare

Step 2: Create Expressions File

sensitive.txt

Step 3: Remove Data

—sensitive-data-removal flag:
  • Fetches all refs (not just branches/tags)
  • Tracks first changed commits
  • Reports orphaned LFS objects
  • Provides cleanup instructions

Step 4: Verify Removal

Step 5: Push and Clean Up

Critical Steps:
  1. Rotate credentials before running filter-repo
  2. Force push to overwrite remote history
  3. Delete all clones and have team members reclone
  4. Clean up code review systems (GitHub PRs, GitLab MRs, etc.)
  5. Remove LFS objects if applicable
See Git Filter-Repo documentation for detailed cleanup procedures.

Binary Files

Skip Binary Files

Remove Specific Binary Types

Common Examples

Remove Accidentally Committed .env File

Fix Typo Throughout History

fixes.txt

Sanitize Configuration Files

Remove Debug Logging

File Mode Changes

Modify file permissions in history:
Valid Git Modes:
  • 100644 - Regular non-executable file
  • 100755 - Executable file/script
  • 120000 - Symbolic link
  • 160000 - Git submodule

Limitations

Regex Limitations
  • Globs and regexes apply to entire file contents
  • No special flags are enabled by default
  • Use (?m) for multi-line mode, (?s) for dot-matches-newline
  • Very large files may cause memory issues
Multiple MatchesIf a pattern matches multiple times in a file, ALL occurrences are replaced.

Next Steps