Why must API keys and access tokens remain outside the Git repository?
Learn why API keys and access tokens belong in protected configuration, how to share safe examples, and what to do if a credential enters Git history.
Why must API keys and access tokens remain outside the Git repository?
API keys and access tokens can authorize actions against external services. In a wedding application, a leaked email token might allow message sending, while a storage credential might expose private photos. Committing these values copies that authority into every repository clone and any other system that receives the history.
Separate application code from credentials
Application code should refer to a configuration name, such as an email-service token variable, without containing its secret value. Developers can use appropriately protected local configuration, while hosted environments should receive secrets through their designated configuration or secret-management facility.
A committed example file can show variable names and clearly fake placeholders. It should explain which service supplies each value and whether the variable is required. This lets an AI agent understand setup without needing production credentials.
Review more than obvious environment files
Secrets can appear in screenshots, copied error messages, test fixtures, scripts, or generated documentation. Inspect the intended commit, including newly added files, and use available secret-scanning protections.
An ignored file is not automatically confidential: local access, logs, or an accidental paste can still expose its contents. Likewise, browser-visible configuration must never contain a private service token, regardless of whether its original file was excluded from Git.
Respond to exposure at the service
If a real token enters shared history, revoke or rotate it promptly. Deleting the current line does not remove earlier copies. GitHub's guidance places credential revocation or rotation before coordinated history cleanup. GitHub secret-removal guidance.
Then replace affected deployment configuration, inspect relevant service activity, and address how the credential was committed. Coordinate any necessary history rewrite with collaborators. The practical goal is to remove the exposed credential's authority and prevent the same release path from leaking its replacement.
No. Repository access, clones, automation, and future sharing create additional exposure paths. Keep the token in protected configuration and commit only the variable name.
Provide the expected environment variable name, a fake example value, and setup instructions. The agent can implement configuration handling without seeing the actual credential.
No. Earlier history or external copies may retain it. Revoke or rotate the token at its service, then coordinate any necessary repository cleanup.
Related learning resources
Ready to master AI completely?
Want to upskill yourself, crack your next interview, and get your dream job? Join our comprehensive course to dive deeper with high-quality video tutorials, solve interview questions, and a premium community.
Master AI
Want to upskill yourself, crack your next interview, and get your dream job? Join our comprehensive course.

