Getting Started

Managing Environment Variables

Push, pull, and organize your secrets across the project, target, and environment hierarchy.

Back to all guides

Once your project hierarchy exists, the day-to-day workflow is pushing secrets up to dotEnv Cloud and pulling them back down where you need them. This guide covers both directions and the most useful flags.

Push secrets from a file

The push command uploads a local .env file to a level in your hierarchy. Secrets are stored as one encrypted blob per level, the inverse of how pull merges them back.

terminal
# Push a .env file to a specific environment
dotenv push my-app/production/api .env
# Push project-wide defaults (apply to all targets/environments)
dotenv push my-app .env.defaults

To populate several levels at once, point the per-level flags at separate files:

terminal
dotenv push my-app --project=.env.project --target=.env.target --env=.env.env

By default a backup version is recorded for every push so you can roll back later. Add --no-backup to skip it, or --force to overwrite existing secrets without a prompt.

Pull secrets back

The pull command retrieves secrets for a level. Because the hierarchy is inheritance-aware, pulling an environment merges in everything defined at the parent target and project levels.

terminal
# Pull the fully merged secrets for an environment
dotenv pull my-app/production/api
# Write them straight to a file
dotenv pull my-app/production/api --output=.env

To inspect only what is defined at a single level, without inheritance, pass --level-only:

terminal
dotenv pull my-app/production/api --level-only

Choose an output format

Both pull and export can render secrets in several formats. The supported values are env (default), json, yaml, shell, and dockerfile.

terminal
# JSON output
dotenv pull my-app/production/api --format=json
# Shell export statements
dotenv export my-app/production/api --format=shell > exports.sh

Resolve variable references

If your secrets reference one another with ${VAR} syntax, pass --resolve to expand them during the pull. See Variable Templating for the full syntax.

terminal
dotenv pull my-app/production/api --resolve

Clear a level

To remove the secrets stored at a level, use secret delete. A backup version is recorded first unless you pass --no-backup:

terminal
dotenv secret delete my-app/production/api

With push and pull mastered, explore the parent-and-child mechanics in Environment Inheritance.