Swiftorial Logo
Home
Swift Lessons
AI Tools
Learn More
Career
Resources

DevSecOps: Scenario-Based Questions

99. What should you do if secrets are accidentally committed to a Git repository?

Committing secrets to Git poses immediate security risks β€” especially in public or shared repos. Prompt detection and remediation are critical to prevent unauthorized access or breaches.

🚨 Immediate Response

  • Revoke the exposed secret (API key, password, token) immediately
  • Notify relevant teams (security, DevOps, product owners)
  • Audit logs for any unauthorized access using the secret

🧹 Cleaning Up Git History

  • Use tools like git filter-repo or BFG Repo-Cleaner to remove secrets from all commits
  • Force-push cleaned history if it’s a private repo
  • If public, consider rotating and invalidating the entire repo if needed

πŸ›‘οΈ Prevention Tools

  • Git hooks or CI checks using tools like Gitleaks, TruffleHog
  • Pre-commit scanners that block committing known patterns
  • Enable secret scanning in GitHub, GitLab, or Bitbucket

βœ… Best Practices

  • Use environment variables or secret managers for sensitive data
  • Audit repos regularly for secrets and credentials
  • Train developers on secure handling and Git hygiene

🚫 Common Mistakes

  • Revoking a secret but not removing it from Git β€” still visible
  • Assuming private repos are safe from scans or leaks
  • No monitoring for leaked secrets usage after exposure

πŸ“Œ Final Insight

Secrets in Git are a high-risk situation β€” treat them like a breach. Automate prevention, react quickly, and educate your team to keep source code secure.