Remove sensitive data from a Git repository

Boris HUISGEN
Boris HUISGEN
Remove sensitive data from a Git repository

Sometimes a sensitive file like a key a token or a certificate has been mistakenly added into a git repository. To remove any trace of it a complete pass of the commits is required.

To filter a specific filename, use this git command:

# git filter-branch --force \
   --index-filter 'git rm --cached --ignore-unmatch path/to/file' \
   --prune-empty --tag-name-filter cat -- --all

The repository should next be force pushed to any remotes.

Boris HUISGEN
Boris HUISGEN
Blog owner
  • #git