# Workflow: environments as branches

## Goal
Dev, staging, and production as branches of one Neon project, with data flowing one direction.

## Steps
1. Production lives on the default (root) branch. Mark it protected.
2. Staging is a long-lived child branch of prod, refreshed nightly via reset from parent.
3. Developers get personal branches from staging or prod, with expiration set (7 days) and anonymization if they carry prod data.
4. Promote by merging code and resetting staging from prod, not by copying data upward; data flows down, code flows up.
5. Scope IP Allow to protected branches so prod is locked down while dev branches stay accessible.

## Ordering constraints
- Protect the prod branch before creating children; the protection must exist before the automation, not after the first accident.
- Anonymize before developers touch prod-derived data.

## Traps
- Long-lived staging drift: without the nightly reset, staging silently stops resembling prod.
- Branch sprawl: personal branches need expiration; audit monthly.
- Connection strings per environment must be separate secrets; one shared string across envs defeats the model.

## Verify
A developer can trace any environment's data to its parent and refresh time; prod has had zero unplanned writes from non-prod tooling.