Sub topic 3
Verifying the Secret Is Gone
Assume you have already rewritten a fresh clone and revoked the leaked credential. Verification must cover every ref, not only the current branch.
Search All Refs
Search for the exact secret in commit history and file contents:
git log --all --oneline -S'AKIAEXAMPLEKEY12345'
git grep -I 'AKIAEXAMPLEKEY12345' $(git rev-list --all) || echo 'no matches'Both checks should produce no secret matches. Also inspect the rewritten repository for unintended changes. Compare important files, run tests, and review recent commit history.
Re-Add the Remote and Force-Push
git filter-repo removes the remote as a safety measure. Re-add it, then update all branches and tags:
git remote add origin [email protected]:org/repo.git
git push --force --all origin
git push --force --tags originForce-pushing replaces the hosting service's branch tips with rewritten commits. Every rewritten commit has a new hash because its ancestry changed. Coordinate a maintenance window and confirm that you have permission before pushing.
Find and Replace Remaining Copies
Hosting platforms may retain unreachable commits, pull request refs, fork objects, or cached views. Follow the platform's documented garbage-collection or support process. Search CI artifacts, release bundles, container images, logs, and backups. A secret in any surviving copy remains compromised.
Tell collaborators to stop using old clones. The safest instruction is to delete the old working copy and clone again. If they must preserve local work, they should export uncommitted changes, make a fresh clone, and reapply the changes carefully. They should not merge old branches into the rewritten repository.
Prevent the Next Leak
Use environment variables or a secret manager instead of committed credentials. Add secret scanning to local hooks and CI. Review .gitignore, limit credential permissions, and rotate credentials regularly.
Exercise
Why is deleting the secret in a new commit insufficient?
Show answer
Earlier commits remain reachable in clones and possibly on the hosting service, so the secret can still be recovered. Revoke it and rewrite history.