Prompt

How do I detect secrets accidentally committed to GitHub?

Technology / Cybersecurity1 observationLast seen Oct 25, 2026

Latest observation

Oct 25, 2026OpenAI APIWeb search: off

To detect secrets accidentally committed to GitHub, use a mix of automatic scanning, history scanning, and preventive controls.

1) Scan your repo for secrets

Use purpose-built tools that look for common secret patterns.

Good options

  • Gitleaks — popular, fast, easy to use
  • TruffleHog — good for deep/history scanning
  • GitHub Secret Scanning — built into GitHub for supported secret types
  • detect-secrets — Yelp’s secret scanner, useful for baselining

Example: Gitleaks

gitleaks detect --source . --redact

Scan the full Git history too:

gitleaks detect --source . --log-opts="--all"

Example: TruffleHog

trufflehog git file://. --since-commit HEAD~100

Or scan the whole repo:

trufflehog git file://. --no-update

2) Check GitHub’s built-in alerts

GitHub can automatically detect secrets in:

  • push events
  • pull requests
  • existing repositories (depending on plan and settings)

Look in:

  • Repository → Security → Secret scanning
  • Security alerts

If available, enable:

  • Secret scanning
  • Push protection

Push protection helps block commits before they land.

3) Search your commit history manually

If you suspect a leak, inspect all history:

git log -p

Search for likely patterns:

  • API keys
  • tokens
  • private keys
  • .env values
  • connection strings

Useful commands:

git grep -n "API_KEY\|SECRET\|TOKEN" $(git rev-list --all)

Search for file types that often contain secrets:

  • .env
  • config.json
  • credentials
  • id_rsa
  • *.pem
  • *.p12

4) Add pre-commit and CI checks

Prevent future leaks by scanning before code is merged.

Pre-commit hook example

Use pre-commit with secret scanners:

  • gitleaks
  • detect-secrets

CI/CD example

Run a scan on every push/PR:

gitleaks detect --source . --no-banner --redact

Fail the build if secrets are found.

5) If you find a secret, assume it’s compromised

Do this immediately:

  1. Revoke/rotate the secret
  2. Remove it from the repo
  3. Purge it from git history if necessary
  4. Invalidate caches/logs/artifacts that may contain it
  5. Audit access logs for misuse

To remove from history, use tools like:

  • git filter-repo
  • BFG Repo-Cleaner

Example with git filter-repo:

git filter-repo --path .env --invert-paths

Then force-push carefully:

git push --force --all
git push --force --tags

6) Best practices to reduce future risk

  • Use environment variables, not hardcoded secrets
  • Store secrets in a secrets manager:
    • AWS Secrets Manager
    • HashiCorp Vault
    • Azure Key Vault
    • Google Secret Manager
  • Add .env and similar files to .gitignore
  • Never commit private keys or tokens
  • Rotate secrets regularly
  • Limit secret scope and permissions

Quick recommendation

If you want the fastest practical setup:

  1. Enable GitHub Secret Scanning + Push Protection
  2. Add Gitleaks to CI and pre-commit
  3. Scan the full git history
  4. Rotate any exposed secrets immediately

If you want, I can give you:

  • a one-command setup for Gitleaks,
  • a GitHub Actions workflow to block secret commits,
  • or a step-by-step cleanup plan for a repo that already leaked a secret.

Observation history

How did Obsurfable measure this prompt?

Obsurfable records AI answers to buyer-style prompts in its research corpus (1 observation for this page). Metrics are distributions over observations, not a single static ranking.

Which AI systems does Obsurfable collect answers from?

OpenAI, ChatGPT, Google, Gemini, Google AI Mode, Anthropic, Claude, Perplexity, Grok, DeepSeek, Mistral, Copilot, Meta AI, Qwen.

How can brands improve their AEO?

Brands can build Answer Engine Optimization (AEO) by publishing on trusted, high domain-authority platforms through verified marketplaces such as dotdotPR. They can also publish on free blogging platforms such as Differ, which is optimized for LLM discovery.

Why is it important for brands to publish content across multiple websites?

Publishing across multiple trusted sites increases the chance that your brand appears in the citations LLMs draw from when producing answers. Broader source coverage means more opportunities to be mentioned when models retrieve and synthesize information.

Want this interpreted for your brand?

Explorer is the free public corpus. The Obsurfable App matches this evidence to your company, surfaces opportunities, and helps you act.