Documentation Index
Fetch the complete documentation index at: https://chatjs.dev/docs/llms.txt
Use this file to discover all available pages before exploring further.
Problem
Schema changes during development can corrupt or pollute your main database. You need isolated environments to test migrations without affecting production data.Solution
Neon’s branching feature creates instant copy-on-write database branches from your main database. Each branch is isolated, cheap (only stores diffs), and can be created/deleted in seconds.Implementation
Setup
Install and authenticate the Neon CLI:.neon file in the current directory (gitignored).
How It Works
Instead of updating.env.local, the branch name is stored in a .neon-branch file (gitignored). The scripts/with-db.sh wrapper reads this file at runtime and injects the correct DATABASE_URL when running database commands.
This means your .env.local stays pointing to main, and branch switching is instant.
Helper Scripts
Thepackage.json scripts use three bash scripts under scripts/:
package.json
Usage
Development Workflow
Commands Reference
| Command | Description |
|---|---|
bun db:branch:start [name] | Create branch and switch to it (default: dev-local) |
bun db:branch:stop [name] | Switch to main and delete branch |
bun db:branch:use [name] | Switch to existing branch (writes .neon-branch) |
bun db:branch:use main | Switch back to main (removes .neon-branch) |
bun db:branch:create [name] | Create branch only |
bun db:branch:delete [name] | Delete branch only |
bun db:branch:list | List all branches |
dev-local if not specified.
Considerations
Benefits:- Instant branch creation (copy-on-write, no data duplication)
- Test destructive migrations safely
- Multiple developers can have separate branches
- Branches inherit data from parent at creation time
- Requires Neon PostgreSQL (not compatible with other providers)
- Branch data becomes stale relative to main over time
- Free tier has limited branch count
- Docker-based local PostgreSQL for full isolation
- Schema-only branches (no data) for simpler cases
- Supabase branching for Supabase users