Skip to main content
Accidentally committing sensitive data like passwords, API keys, or credentials is a common mistake. git-filter-repo provides powerful tools to completely remove this data from your repository history.
After removing sensitive data from history, you must:
  • Rotate any exposed credentials immediately
  • Force push the cleaned repository
  • Ask all team members to re-clone (not pull) the repository
  • Consider the data compromised if it was ever pushed to a public repository

Removing Specific Files

To remove a file containing sensitive data from all of history:
1

Clone a fresh copy

2

Remove the file

The --invert-paths flag removes the specified path instead of keeping it.
3

Verify removal

4

Force push

Force pushing rewrites history. Coordinate with your team before doing this.

Removing Multiple Files

For removing many files at once, create a file listing all paths to remove:
1

Create the paths file

Create ../files-to-delete.txt with one path per line:
2

Remove all listed files

Removing Files by Pattern

Remove all files matching a specific pattern:

Replace Text in Files

For removing sensitive strings embedded in files (like API keys in code):
1

Create a replacements file

Create ../replacements.txt with the format FIND==>REPLACE:
You can also use regex patterns:
2

Apply replacements

Advanced: Using Callbacks

For complex removal scenarios, use Python callbacks:

Remove specific blob by hash

If you know the hash of a sensitive blob:

Remove files with specific patterns in name

Removing a Directory

To remove an entire directory from history:

Complete Cleanup Workflow

1

Create a fresh clone

2

Remove sensitive data

3

Verify the cleanup

4

Replace the remote repository

5

Rotate credentials

Change all exposed passwords, API keys, and credentials immediately.
6

Notify team members

Instruct all contributors to delete their local clones and re-clone:
Do not use git pull - it will bring back the old history!

Post-Cleanup Checklist

  • All sensitive credentials have been rotated
  • Force push completed successfully
  • All team members notified to re-clone
  • GitHub/GitLab support contacted (if needed for server-side cleanup)
  • Repository size reduced as expected
  • CI/CD secrets updated
  • Documentation updated with new credentials (in secure storage)