Skip to main content

Sync Command Options

The sync command synchronizes environment variable keys across all .env* files in your project directory.

Command Usage

env-twin sync [options]

Options

--no-backup
boolean
default:"false"
Skip creating a backup before syncing. By default, env-twin creates a timestamped backup in the .env-twin/ directory before making any changes.Warning: Using this option means you won’t have an automatic rollback point if something goes wrong.Example:
env-twin sync --no-backup
--yes
boolean
default:"false"
Skip confirmation prompts and auto-accept non-destructive actions. This is useful for CI/CD pipelines or automated workflows.Aliases: -yExample:
env-twin sync --yes
env-twin sync -y
--json
boolean
default:"false"
Output the analysis report in JSON format instead of the interactive CLI interface. This is useful for programmatic consumption or AI-powered tools.Example:
env-twin sync --json
env-twin sync --json > report.json
--source
string
Specify the “Source of Truth” file. Keys will be synced FROM this file to other .env* files. If not specified, env-twin will prompt you to choose or use a union of all files.Aliases: --srcExample:
env-twin sync --source .env.example
env-twin sync --src .env.production

How Sync Works

The sync command performs the following operations:
  1. Detects all .env* files in the current directory (.env, .env.local, .env.development, .env.testing, .env.staging, .env.example)
  2. Analyzes differences between files
  3. Interactively asks how to resolve missing keys (Add Empty, Copy Value, Skip)
  4. Ensures .env.example contains all keys with placeholder values
  5. Preserves existing values and file structure
  6. Creates a backup in .env-twin/ before modifying files (unless --no-backup is used)

Usage Examples

Basic Sync

env-twin sync

Sync with Specific Source

env-twin sync --source .env.example

JSON Output for Automation

env-twin sync --json

Skip Confirmations

env-twin sync --yes
env-twin sync --no-backup

Combined Options

env-twin sync --source .env.example --yes --json

Build docs developers (and LLMs) love