Skip to content
Software capabilities
Neon

Create a Neon preview database branch

Create a branch for preview or test data through Neon’s API or CLI. Add a read-write compute endpoint when the branch needs to accept connections.

Documentation reviewed · 2 methods with sources

Ways to do it

  1. API: POST /api/v2/projects/{project_id}/branches
  2. CLI: neon branches create
API

POST /api/v2/projects/{project_id}/branches

Create a branch in a Neon project from its default branch or a specified parent branch.

Read source: Neon create project branch API
Requirements
A Neon API key authorized for the project and the project ID. Supply a parent branch ID when the default branch is not the intended source.
Limitations
The API creates a branch without a compute endpoint by default. Add a read-write endpoint before connecting; each branch supports one read-write endpoint and multiple read-only endpoints.

Example shell

curl --fail -X POST "https://console.neon.tech/api/v2/projects/$PROJECT_ID/branches" -H "Authorization: Bearer $NEON_API_KEY"
CLI

neon branches create

Create a named branch with the Neon CLI and optionally connect to its new branch.

Read source: Neon CLI branches
Requirements
The Neon CLI authenticated with access to the target project, and a project ID or current project context.
Limitations
The CLI creates a read-write compute by default. Use Neon CLI 4.9.0 or later with --no-secrets to omit the connection string from output.

Example shell

neon branches create --project-id "$PROJECT_ID" --name preview-branch --no-secrets