How to Manage Environment Variables Across Dev, Staging and Production

A practical guide to managing environment variables across local, staging and production: naming, storage, access control, sync and a checklist your team can adopt today.

What environment variables are for

Environment variables hold configuration that changes between deployments: database URLs, API keys, feature flags and service endpoints. The twelve-factor app methodology recommends keeping this config in the environment, separate from code, so the same build can run anywhere.

The trouble starts when the values themselves have no home. They end up in a local .env file, a chat message, a wiki page and a CI settings screen, and no two copies agree.

Separate environments from the start

Most teams need at least three environments: development, staging and production. Keep each one as its own set of values so a staging key can never be mistaken for a production key.

Use the same variable names in every environment and change only the values. Code that reads DATABASE_URL then works everywhere, and a missing key is easy to spot because it is missing from one environment but present in the others.

  • Name keys in UPPER_SNAKE_CASE and group them with a prefix, such as STRIPE_ or SMTP_.
  • Keep a .env.example in the repo with every key and no real values.
  • Never commit a real .env file. Add it to .gitignore on day one.

Store secrets centrally, not on laptops

A central, encrypted store gives you one place to rotate a key and one place to audit who changed it. Developers pull the values they are allowed to see instead of asking a teammate to paste them.

With Qikenv, a developer links a folder to a project and environment once, then syncs from the terminal.

npm install -g qikenv-cli
qikenv login
qikenv link
qikenv pull

Control who can change what

Development values should be easy to edit. Production values deserve friction. Role-based access lets everyone on the team read what they need while limiting who can write to production.

Keep a change history as well. When a deploy breaks, the first question is usually which variable changed and who changed it.

Check for drift before you ship

Drift is when a local .env no longer matches the environment it came from. Run a status check before you push or deploy so you see what is synced, changed, local-only or remote-only.

qikenv status

A checklist you can adopt this week

If you only do five things, do these:

  • Create one environment per stage and keep key names identical across them.
  • Move every secret out of chat, docs and tickets into one encrypted store.
  • Give each teammate access only to the projects and environments they work on.
  • Make production writes owner-only.
  • Run a drift check as part of your release routine.

Frequently asked questions

Should I commit my .env file to Git?

No. A real .env file contains secrets and should be in .gitignore. Commit a .env.example with the key names and no values instead.

How many environments do I need?

Three is a good default: development, staging and production. Add more only when you have a clear reason, such as a per-branch preview environment.

What is the difference between a .env file and a secrets manager?

A .env file is a local file read at startup. A secrets manager stores the values centrally with encryption and access control, then delivers them to the machines that need them.