With Neon, you can quickly branch your data for development, testing, and various other purposes, enabling you to improve developer productivity and optimize continuous integration and delivery (CI/CD) pipelines.

You can also rewind your data or create branches from the past to recover from mistakes or analyze historical states.

What is a branch?

A branch is a copy-on-write clone of your data. You can create a branch from a current or past state. For example, you can create a branch that includes all data up to the current time or an earlier time.

working with sensitive data?

Neon also supports schema-only branching. Learn more.

A branch is isolated from its originating data, so you are free to play around with it, modify it, or delete it when it's no longer needed. Changes to a branch are independent. A branch and its parent can share the same data but diverge at the point of branch creation. Writes to a branch are saved as a delta.

Creating a branch does not increase load on the parent branch or affect it in any way, which means you can create a branch without impacting the performance of your production database.

Each Neon project is created with a root branch called main. The first branch that you create is branched from the project's root branch. Subsequent branches can be branched from the root branch or from a previously created branch.

Using Neon Auth?

Users, sessions, and auth configuration in the neon_auth schema branch with your data, so preview and test environments get isolated authentication state. See Neon Auth and Branching authentication.

Branching workflows

You can use Neon's branching feature in variety workflows.

Development

You can create a branch of your production database that developers are free to play with and modify. By default, branches are created with all of the data that existed in the parent branch, eliminating the setup time required to deploy and maintain a development database.

development environment branch

The following video demonstrates creating a branch in the Neon Console. For step-by-step instructions, see Create a branch.

You can integrate branching into your development workflows and toolchains using the Neon CLI, API, or GitHub Actions. If you use Vercel, you can use the Neon-managed Vercel integration to create a branch for each preview deployment.

Refer to the following guides for instructions:

Testing

Testers can create branches for testing schema changes, validating new queries, or testing potentially destructive queries before deploying them to production. A branch is isolated from its parent branch but has all of the parent branch's data up to the point of branch creation, which eliminates the effort involved in hydrating a database. Tests can also run on separate branches in parallel, with each branch having dedicated compute resources.

test environment branches

Refer to the following guide for instructions.

Temporary environments

Create branches with TTL by setting an expiration date. Perfect for temporary development and testing environments that need automatic deletion.

Branches with expiration work well for:

  • CI/CD pipeline testing environments
  • Feature development with known lifespans
  • Automated testing scenarios
  • AI-driven development workflows

Restore and recover data

If you lose data due to an unintended deletion or some other event, you can use instant restore to recover: roll the branch back to any point in time that still falls within your project's history window (the retention you configure under Settings → Instant restore). You can also create a new restore branch for historical analysis or any other reason.

Recover from data loss using restore branching

History window

Instant restore (and Time Travel, branching from the past, and snapshots) need Neon to keep a log of data changes. The history window is the project-wide setting—on Settings → Instant restore in the Console—that controls how long that change history is retained, which sets how far back instant restore and the other features can reach.

Neon retains a history of changes for your branches, with defaults of 6 hours on Free plan and 1 day on paid plans. Increasing the history window expands recovery options but also increases storage costs, as more history is kept. You can configure it up to 7 days on Launch or 30 days on Scale plans.

For limits, billing, and how to change the setting, see History window.

Learn how to use these data recovery features: