Skip to content

blemli/envsync

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Sync Laravel .env files

Latest Version on PackagistGitHub Tests Action StatusGitHub Code Style Action StatusTotal Downloads

A powerful Laravel package for synchronizing environment files with interactive prompts and intelligent conflict resolution. EnvSync helps you keep your .env, .env.example, .env.production and other environment files in perfect harmony.

Caution

🤖🧠 This Package was vibe coded 🤖🧠

Key Features:

  • 🔄 Interactive Sync: Per-key prompts for differing values with sync, ignore, or permanent ignore options
  • 🚫 Smart Ignoring: Use #ENVIGNORE comments to permanently ignore specific environment variables
  • 📁 Structure Preservation: Maintains file formatting, comments, and organization
  • Auto-sync Mode: Automatically sync all differences without prompts
  • 🔒 Version Control Aware: Handles version-controlled files intelligently

Installation

You can install the package via composer:

composer require blemli/envsync

Usage

Basic Sync

Sync your .env file with .env.example:

php artisan env:sync

Sync with a different target file:

php artisan env:sync --path=.env.production

Interactive Mode (Default)

When differences are detected, you'll get interactive prompts for each differing key:

Key 'DATABASE_URL' has different values:
  .env: 'mysql://localhost/prod_db'
  .env.example: 'mysql://localhost/example_db'

What would you like to do with this key?
  [0] Sync from .env to .env.example
  [1] Ignore once (skip this time only)
  [2] Forever ignore (add #ENVIGNORE to this line)
  [3] Quit without making changes

Auto-Sync Mode

Automatically sync all differing values without prompts:

php artisan env:sync --auto-sync

Force Mode

Skip all confirmation prompts and apply all changes automatically:

php artisan env:sync --force

Permanent Ignoring with #ENVIGNORE

Add #ENVIGNORE to any line in your target file to permanently ignore differences for that key:

# .env.example
APP_NAME=ExampleApp
DATABASE_URL=mysql://localhost/example_db #ENVIGNORE
API_KEY=your_api_key_here

The DATABASE_URL line will be ignored in all future sync operations.

Examples

Scenario 1: New developer setup

# Copy .env.example to .env, then sync any missing keys
cp .env.example .env
php artisan env:sync --path=.env.example

Scenario 2: Production deployment

# Sync production environment file
php artisan env:sync --path=.env.production --auto-sync

Scenario 3: Team collaboration

# Interactive sync to review each difference
php artisan env:sync --path=.env.example

Command Options

Option Description
--path=FILE Target file to sync with (default: .env.example)
--force Skip all confirmation prompts and apply changes automatically
--auto-sync Automatically sync all differing values from source to target

How It Works

  1. Missing Keys: Prompts to add keys that exist in source but not in target
  2. Extra Keys: Prompts to remove keys that exist in target but not in source
  3. Differing Values: Interactive prompts with options to sync, ignore once, or ignore forever
  4. Version Control: Automatically detects version-controlled files and handles them appropriately
  5. Structure Preservation: Maintains original file formatting, comments, and organization

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.

About

synchronize env files

Resources

License

Stars

Watchers

Forks

Sponsor this project

Packages

 
 
 

Contributors

Languages