Git History Secret Mining
Git history retains every version of every file ever committed — including credentials deleted last week, tokens rotated last month, and passwords removed years ago. Secret mining scans the complete commit graph across all branches and tags, not just the current working tree. Even a clean repository head can have a rich history of secrets. Run this after cloning the full repository with all branches via repository cloning.
Automated Scanning with trufflehog
trufflehog scans every commit across all branches for high-entropy strings and known secret patterns:
Found verified result 🐷🔑 Detector Type: AWS Decoder Type: PLAIN Raw result: AKIAIOSFODNN7EXAMPLE Commit: b2c3d4e5f6 Filename: config/aws.yml Line: 3
Scan with gitleaks
gitleaks is faster on large repositories and has good rule coverage for common secret types:
"Secret": "SuperSecret123!", "File": ".env", "Commit": "a1b2c3d4", "Match": "DB_PASSWORD=SuperSecret123!"
Manual Search Through All Commits
When automated tools miss things or you want targeted searches, use git log to search commit content directly:
+DB_PASSWORD=OldP@ssword2023! +API_TOKEN=sk-prod-oldkey123 -DB_PASSWORD=OldP@ssword2023! +DB_PASSWORD=NewP@ssword2024!
a1b2c3d fix: remove hardcoded API key from .env b2c3d4e add production database credentials c3d4e5f initial commit
commit a1b2c3d... -API_KEY=sk-prod-xK2aB1cD3eF4gH5i +API_KEY=REDACTED
Check Stashes
Developers sometimes stash work-in-progress changes that contain incomplete or experimental credentials — stashes are included in the repo object store and cloned with the repository:
stash@{0}: WIP on develop: testing new API key
stash@{1}: WIP on main: temp credentials for debug
+API_KEY=sk-test-newkeyABC123 +DEBUG_PASSWORD=tempP@ss!
Search for Private Keys
+-----BEGIN RSA PRIVATE KEY----- +MIIEowIBAAKCAQEA...
uid=0(root) gid=0(root) groups=0(root)
Full Automated Sweep
Combine multiple searches in one pass across all cloned repositories:
=== repo === +DB_PASSWORD=SuperSecret123! +AWS_SECRET_ACCESS_KEY=wJalr... === webapp === +STRIPE_KEY=sk_live_abc123...
References
-
Secret scanning across git history with verified credential detection
-
Fast git history secret scanning with JSON report output
Was this helpful?
Your feedback helps improve this page.