remove-secrets

Permanently purges sensitive files from the entire Git history.

Usage

git-wrangler remove-secrets [--repo <path>] [--yes] [--no-fetch] [--guided]

The command prompts before any destructive history rewrite is performed. Use --yes to proceed noninteractively.

What it does

Discovers Git worktrees under the current directory, or targets exactly one worktree with --repo, scans history for common secret file patterns, and removes matches with git-filter-repo.

The rewrite uses --path-glob, --invert-paths, --partial, and --force. The remote origin URL is automatically restored after the rewrite.

By default, remove-secrets first runs git fetch --prune origin for each target repository before scanning. Any fetch failure stops the command before scan, preview, confirmation, or mutation. Use --no-fetch for offline or local-only runs; the command warns that local remote-tracking refs may miss remote-only commits.

Target patterns

The following patterns are scanned and removed if found in history:

Pattern groupExamples
Environment and package credentials.env, .env.*, .npmrc, .pypirc, .netrc, .git-credentials
Private keys and certificates*.pem, *.key, *.p12, *.pfx, *.asc, *.gpg, *.crt, *.cer, *.cert
SSH keysid_rsa, id_rsa.pub, id_ed25519, id_ed25519.pub, *_rsa, *_ed25519
Secret storessecrets.json, credentials.json, *secret*.json, *credential*.json, *.secret, config/credentials.yml.enc
Container and Kubernetes credentials.docker/config.json, .kube/config, kubeconfig
Cloud credentials.aws/credentials, .aws/config, .config/gcloud/*, application_default_credentials.json, azureProfile.json, accessTokens.json

Prerequisites

  • git-filter-repo must be installed

Options

FlagRequiredDescription
--repo <path>OptionalTarget exactly one repository instead of discovering recursively.
--yesOptionalSkip confirmation prompts.
--no-fetchOptionalUse local remote-tracking refs without fetching origin first.
--guidedOptionalInteractively configure command options before execution.

Example

git-wrangler remove-secrets --yes

# Scan using local remote-tracking refs without refreshing origin
git-wrangler remove-secrets --no-fetch

Notes

Warning: This permanently rewrites Git history. You will need to force-push to update remotes, and collaborators must coordinate after the force push, often by re-cloning or resetting.

  • The command scans history first and reports found files before prompting to remove them
  • Generic config.json files are not removed unless they match a credential-specific path such as .docker/config.json
  • Repositories with no matching patterns are skipped cleanly
  • Remote origin is preserved and restored after the rewrite