Git Hooks and CI/CD

dotenv-diff is a CLI-first tool and does not manage git hooks or CI workflows by itself. Instead, it is designed to integrate cleanly with existing tooling such as pre-commit hooks or GitHub Actions.

Using dotenv-diff as a Pre-Commit Hook

Running dotenv-diff before each commit helps catch missing or misused environment variables early — before they reach CI or production.

A common setup is to use husky together with lint-staged. This allows dotenv-diff to run automatically whenever files are committed.

Running dotenv-diff in GitHub Actions

dotenv-diff can also be used as part of your CI pipeline to ensure environment variable consistency across pull requests.

This is especially useful to verify that .env.example stays in sync with actual code usage.

Example GitHub Action

.github/workflows/dotenv-diff.yml
name: dotenv-diff

on: [pull_request]

jobs:
  env-validation:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v6
      - uses: actions/setup-node@v6
      - run: npm install
      - run: npx dotenv-diff --example .env.example --strict

Why

  • To prevent commits that introduce undocumented environment variables.
  • To catch framework-specific env usage issues early.

Best Practices

  • Use --example to specify the example environment file for validation.