Skip to content

In development. Expect rough edges and changes. The source code is not public yet.

Neon 8 min read How-to mediumAdept

Automating Neon branch creation with Githooks

A Git post-checkout hook can create a Neon database branch for each new Git branch, giving every feature branch an isolated copy of the main Postgres database without a local install or seed scripts. The shell script reads the hook's arguments to detect branch checkouts and counts reflog entries to spot first-time checkouts. It asks the user for confirmation via /dev/tty, checks the Neon API for an existing branch, creates one with a POST request, and uses jq to write the returned connection URI to .env as DATABASE_URL.

Assumes: shell scriptingGit basicsREST APIs

Related posts

  • A branch-first dev loop for Neon: link, checkout and env pull

    Neon mediumAdept

    Neon's CLI adds three commands for branch-first Postgres development. `neon link` binds a workspace to a project and branch via a git-ignored `.neon` file. `neon checkout` creates or switches database branches, much like `git checkout -b`. `neon env pull` writes only the Neon-managed connection strings and service secrets for the current branch into `.env`. Link and checkout run env pull automatically, which suits coding agents that need an isolated database per feature. Teams that keep secrets off disk can pass `--no-env-pull` and inject env at runtime with `@neondatabase/env` (`neon-env run`, `fetchEnv`) or export it into varlock.

  • Branching Postgres databases with the Neon API

    Neon mediumAdept

    Neon branches are copy-on-write clones of a Postgres database that can be created and deleted through the Neon API, giving CI pipelines an isolated copy of production data for end-to-end tests. Two experimental GitHub Actions, neondatabase/create-branch-action and neondatabase/delete-branch-action, wrap the API. A sample pull-request workflow creates a branch from a parent branch, runs the test steps, then deletes the branch. The actions were beta at the time and still being hardened for production use.

  • Just landed in the Neon CLI

    Neon mediumAdept

    The Neon CLI is renamed from neonctl to neon (old name kept as an alias) and gains a branch-first workflow built on `neon link`, `neon checkout` and `neon env pull`, which store project/branch context in a local .neon file and rewrite only Neon-managed env vars. New commands include `neon inspect db` for read-only Postgres diagnostics (bloat, unused indexes, locks, pg_stat_statements outliers, cache hit rate), `neon diff` for git-style schema diffs, snapshots, project-scoped API keys and credential profiles for CI and agents, and a raw `neon api` fallback. `neon init` sets up MCP and agent skills in one step, and a suggested AGENTS.md snippet steers coding agents toward the branch-per-feature loop.

  • Adopting Neon branching in CI/CD pipelines: a practical story by Shepherd

    Neon mediumAdept

    Shepherd, an insurtech startup that moved its Alchemist pricing engine from SQLite to Postgres, uses Neon's copy-on-write database branches to give every pull request an ephemeral test database. GitHub Actions call the Neon API to create a branch when a PR opens and delete it on merge. Changes then flow from per-developer and per-PR branches to staging and production, with Render pre-deploy commands applying migrations tracked in a dedicated timestamped table. The team credits branching with removing the cost and effort of keeping test instances synced with production, and notes that scale-to-zero means it no longer pays for idle databases.

  • Fullstack preview environments using Neon and Qovery

    Neon mediumAdept

    Each Qovery preview environment can get its own isolated Postgres database by using a Qovery lifecycle job that creates a copy-on-write Neon branch on the environment's Start event and deletes it on Delete. A Docker image bundles the Neon CLI and two shell scripts. create-branch.sh creates a branch named after QOVERY_ENVIRONMENT_NAME and writes direct and pooled connection strings to /qovery-output/qovery-output.json, so other services receive them as environment variables. delete-branch.sh looks up the branch ID through the Neon API and deletes it. This sidesteps the conflicts of a shared preview database and the slow provisioning, stale seed scripts and privacy issues of copying production data.

The quest for software engineering knowledge.

Look:
Layout: