Is it okay to commit a config-only .env file to a private repo?

November 18, 2026 4 answers
Asked by 6e+trufflebracket_315

Several private repos use .env files for secrets, server addresses and runtime tuning. Secrets will stay out of Git, but can the non-secret settings go in the repos? How do you handle private IPs and keep config separate from credentials?

Answers

_c57+ploverwrench.3

Yes, a config-only file can go in the repo. The security question is about what it contains, not the .env extension. Versioning worker counts, timeouts and log levels gives you review and history instead of mystery changes on a server.

I would keep a committed template such as .env.dist with safe defaults, and ignore .env.local and .env.secrets. Make the loading order explicit so a local override doesn't unexpectedly replace a deployment value. Check that your application or deployment tooling actually loads those files in the order you intend.

m.682~zindelo:

A template also makes it easier to see which variables are expected without handing new developers a copy of a live environment file.

Reply to this answer
_x37!torvexa.9

The main objection is accidental secret commits. Someone sees a tracked .env, adds a token while testing, and it goes into history with an otherwise harmless change.

Use a clearly named config file or template, keep secret-bearing files ignored, and run secret scanning in CI. Review config changes too. Scanning helps catch mistakes, but it doesn't prove a file is secret-free.

6e+trufflebracket_315:

That makes sense. A different filename might make the boundary clearer, even if the contents still need review.

Reply to this answer
7m!fennelspanner_428

Private IPs aren't passwords, but they can reveal infrastructure layout. A private repo reduces exposure, it doesn't make that information harmless to everyone who can access the code or its copies. Decide based on who needs the addresses and what access they enable.

There's also a maintenance issue. If the same addresses live in three repos, a server change can leave them out of sync. Infrastructure configuration or service discovery may be a better home for them.

Reply to this answer
r.738~plumgauge

Separate build configuration from deployment-specific configuration. Keep shared defaults in version control, then generate or substitute server-specific values during deployment. That works better when worker counts depend on the machine or when hosts change.

For the split across repos, deployment automation can assemble the appropriate non-secret settings and retrieve credentials from a secret manager at runtime. Document which source owns each setting and which value wins if there are overrides.

5x~quarrywhistle_692:

Deployment automation can also manage the resulting environment files, rather than relying on someone to copy them between servers.

Reply to this answer

Add your answer

Answers are reviewed before publication.

Related Discussions