🔑developer

Environment Variables Done Right: Stop Committing Secrets to Git

Environment variables manage config between environments, but most teams use them wrong. Here's the right approach — from .env files to production secrets management.

6 min readJanuary 18, 2026Updated February 12, 2026By FreeToolKit TeamFree to read

Frequently Asked Questions

What should and shouldn't go in environment variables?+
Environment variables are appropriate for: database connection strings and credentials, API keys and secrets, service URLs that differ between environments, feature flags controlled per environment, logging levels, port numbers, and any value that differs between development, staging, and production. They're not appropriate for: configuration that belongs in code (algorithm choices, data structure sizes), secrets that need rotation without redeployment (use a secrets manager), large config that would be unwieldy as env vars (use a config file), or sensitive data that needs audit logging (use a proper secrets management system like Vault, AWS Secrets Manager, or similar).
Is it safe to commit .env files to version control?+
Never commit .env files containing real credentials. The file should be in your .gitignore immediately when you create it. Instead, commit a .env.example or .env.template file with all the keys but no values (or dummy placeholder values), so new developers know what variables to set up. The danger of committed secrets is permanent: even after deleting the file, the secret exists in git history and can be extracted with standard git commands. If you accidentally commit a secret, treat it as compromised immediately — rotate the credential before addressing the git history. GitHub secret scanning can catch some exposed secrets automatically.
How should environment variables be managed in production?+
In production, avoid .env files entirely. Use your platform's native secrets management: Vercel environment variables, AWS Secrets Manager, Azure Key Vault, GCP Secret Manager, Kubernetes Secrets, or HashiCorp Vault. These systems provide access control (only authorized services can read a secret), audit logging (who read or changed what and when), rotation support (change the secret without changing code), and environment scoping (production can access prod secrets, staging cannot). For container-based deployments, inject environment variables at runtime rather than baking them into the image. Never include secrets in Docker images.

🔧 Free Tools Used in This Guide

FT

FreeToolKit Team

FreeToolKit Team

We build free browser tools so you don't have to install anything.

Tags:

environment-variablessecuritydevopsconfigurationsecrets