This repository provides a custom pre-commit hook that identifies .env*
files and generates .example
versions with sensitive data removed, while preserving port numbers.
- The script searches for all
.env*
files (excluding.example
files). - It creates an
.example
version of each.env
file. - Sensitive information is removed, except for port numbers.
- The original
.env
file is added to.gitignore
if it's not already present. - The
.env.example
files are automatically staged for commit.
-
Add this repository to your project’s
.pre-commit-config.yaml
:repos: - repo: https://github.com/nicballarini/env-sanitizer rev: v1.0.6 hooks: - id: sanitize-env-files
-
Install pre-commit in your project:
pre-commit install
-
Now, every time you commit changes, the
.env
files will be sanitized and.example
copies will be generated automatically.
MIT License