Keep your repository secure. Prevent secrets in code, protect branches, and maintain a clean git history.
API keys, passwords, and credentials should never be in your repository—even in private repos.
Set up .gitignore before adding any files. Once secrets are committed, they're in history forever.
Protect main branches from direct pushes. Require reviews and status checks.
Signed commits prove authenticity. Important for supply chain security.
Automatically detect secrets that were accidentally committed.
.env .env.* *.pem *.key *.p12 *credentials* *secret* .aws/ .gcloud/ node_modules/ .DS_Store *.sqlite *.db config/local.json config/production.json
Add this to your .gitignore before making your first commit. Customize based on your stack.
AWS tool to prevent committing secrets
brew install git-secrets && git secrets --installFramework for managing pre-commit hooks
pip install pre-commit && pre-commit installScan git repos for secrets
brew install gitleaksFind credentials in git history
brew install trufflehogVAS scans your deployed application for exposed credentials and API keys— the kind of secrets that end up in git history.
Free Security Scan1) Rotate the secret immediately—assume it's compromised, 2) Remove from history using git filter-branch or BFG Repo Cleaner, 3) Force push (coordinate with team), 4) Enable secret scanning to prevent recurrence. Note: If pushed to public repo, bots may have already captured it.
No. Private repos still have risks: team members leaving, accidental public exposure, compromised accounts, repo cloning. Never put secrets in git, even in private repos. Use environment variables, secret managers, or CI/CD secrets.
For most projects, it's nice-to-have. For security-sensitive or open-source projects, it's important—it proves commits came from who they claim. Required for some compliance frameworks. At minimum, enable for main branch merges.
Use trufflehog: `trufflehog git file://./` or gitleaks: `gitleaks detect`. These scan entire history. For ongoing protection, use pre-commit hooks to prevent new secrets from being added.
Environment files (.env), key files (*.pem, *.key), local config (config/local.json), credentials files, database files (*.sqlite), dependencies (node_modules/), OS files (.DS_Store), IDE config (.idea/, .vscode/).
Last updated: January 16, 2026