Guides

How to back up .env files (without committing them)

Every guide says to keep .env out of git, and they're right. But then the only copy of your production database URL and API keys is a plain text file on one laptop. Here are four ways to keep a second copy, and what each one costs you.

Updated October 31, 2026

First: what you're actually backing up

It's rarely just .env. A typical machine also has .env.local and .env.production, .dev.vars for Cloudflare Workers, .envrc for direnv, Terraform *.tfvars, Firebase service account JSON files and mobile signing keystores. Some of these hold values you can't get back: a keystore that signs an Android app, or an API key the service showed you once.

Before picking a method, make sure every one of them is ignored. git check-ignore prints the files that are ignored, so any file missing from its output isn't:

git check-ignore -v .env .env.local .dev.vars
git ls-files | grep -E '(^|/)\.env($|\.)' | grep -vE '\.(example|sample|template)$'   # committed already?

If the second command prints anything, that secret is in your git history. Remove the file, and treat the values as leaked: change them at the service.

Option 1: a password manager

Paste each .env into a secure note in 1Password, Bitwarden or Apple Passwords.

  • Good: you already have one, it's encrypted, and it syncs.
  • Bad: it's manual. The note is right the day you paste it and wrong a week later when you add a key. Restoring 30 projects means 30 copy and pastes into the right folders.

Fine for two or three projects that rarely change.

Option 2: encrypted files in git (SOPS, git-crypt, dotenvx)

Encrypt the file and commit the encrypted version next to your code. With SOPS and an age key:

age-keygen -o ~/.config/sops/age/keys.txt
sops --encrypt --age age1… .env > .env.enc    # commit .env.enc, keep .env ignored
sops --decrypt .env.enc > .env               # on another machine
  • Good: secrets are versioned with the code and shared with everyone who has the key. Works on any OS and in CI.
  • Bad: it's a per-repo setup you have to remember, and you've moved the problem rather than solved it: the age key on your laptop now needs a backup of its own. Lose it and every encrypted file is unreadable.

The right choice for a team repo with CI. Overkill for 20 side projects.

Option 3: a hosted secrets manager

Doppler, Infisical, AWS Secrets Manager and similar services hold the secrets on their side, and your app gets them at runtime (doppler run -- npm start) instead of from a file.

  • Good: one place for secrets across a team, environments and CI, with access control and audit logs.
  • Bad: another account and usually a per-seat subscription. Your secrets are on someone else's servers, and every project has to be wired to it. Doesn't cover SSH keys, keystores or certificates.

Worth it for a team running production systems. We wrote a longer comparison in a Doppler alternative for solo developers.

Option 4: an encrypted backup of the files themselves

Leave your workflow exactly as it is, with .env files on disk where your tools expect them, and back those files up, encrypted, somewhere that isn't your laptop. You can do this by hand with an encrypted disk image:

hdiutil create -encryption AES-256 -srcfolder ~/secrets-staging -format UDZO secrets.dmg

But then you also need a script to collect the files into ~/secrets-staging and remember where each one came from, plus a schedule to run it. Otherwise it's out of date, just like the password manager note.

Comparison

AutomaticRestores into placeCovers keys and certsNo new account
Password managerNoNoPartlyYes
SOPS / git-cryptPer commitYesPer repoYes
Hosted secrets managerYesRuntime onlyNoNo
Encrypted backup (by hand)If scriptedNoYesYes
VaultDailyYesYesUses your iCloud

What we use: Vault

Vault is option 4 without the scripts, for the Mac. It scans your project folders for .env files, keys, certificates and service credentials, encrypts them on your Mac with ChaCha20-Poly1305, and stores them in your own iCloud, not on our servers. It runs every day, keeps a history of every change, and warns you when a secret is committed to git or missing from .gitignore. On a new Mac, it puts every file back into the right folder.

If you already use SOPS or a hosted manager for team projects, Vault still covers what those don't: your personal projects, SSH keys and the age key itself.

Back up every .env on your Mac in two minutes.

Free for 3 projects, plus your home folder and Apple developer keys. macOS 14 or later.

Download Vault