What kinds of files commonly leak secrets, and how does .gitignore help?
BeginnerConceptGitleaks
Answer
Short answer
The usual suspects are .env files, cloud credential files (~/.aws/credentials, service account JSON), Terraform state and tfvars, kubeconfig files, private keys/certificates, and app config like application-prod.yml. A good .gitignore stops these files from being added to Git in the first place.
Example .gitignore section
# secrets & credentials
.env
.env.*
!.env.example
*.pem
*.key
*.p12
id_rsa*
kubeconfig
*.kubeconfig
credentials.json
service-account*.json
# terraform
*.tfstate
*.tfstate.*
*.tfvars
!example.tfvars
.terraform/
Important limits
.gitignoreonly affects untracked files. If a file was already committed, ignoring it later does nothing — remove it withgit rm --cached(and rotate what was in it).- It doesn't catch secrets pasted inside normal code files — that's what Gitleaks is for.
Pattern teams use
Commit an .env.example with placeholder values so developers know which variables to set, while the real .env stays ignored.
What to say in the interview
"Env files, cloud credential files, tfstate and tfvars, kubeconfigs and private keys are the common leakers. We gitignore them with a committed .env.example as a template, remember that gitignore doesn't untrack already-committed files, and rely on Gitleaks for secrets inside code."
More on Gitleaks
What is Gitleaks and how do you use it?BeginnerWhat is a secret leak and why is it dangerous?BeginnerWhat is Gitleaks?BeginnerHow do you scan a repository's full history with Gitleaks and create a report?BeginnerHow do you stop secrets before they're committed using a pre-commit hook?BeginnerHow do you run Gitleaks in a CI pipeline and fail the build on findings?Beginner