Skip to main content
Lakebase Postgres is built on object storage, but 99.99999% of reads are served from high-performance local caches

Manage branches

View as Markdown

Data resides in a branch. Each Neon project is created with a root branch, which is also designated as your default branch. Projects created in the Neon Console have a root branch named production, while projects created via the API or CLI have a root branch named main. You can create child branches from your root branch or from previously created branches. A branch can contain multiple databases and roles. Neon's plan allowances define the number of branches you can create.

A child branch is a copy-on-write clone of the parent branch. You can modify the data in a branch without affecting the data in the parent branch. For more information about branches and how you can use them in your development workflows, see Branching.

You can create and manage branches using the Neon Console, Neon CLI, or Neon API.

important

When working with branches, it is important to remove old and unused branches. Branches hold a lock on the data they contain, which will add to your storage usage as they age out of your project's history window.

Branch naming requirements

Specifying a branch name is optional. If you don't provide one, the branch name defaults to the automatically generated branch ID with a br- prefix (for example, br-curly-wave-123456).

If you do specify a custom branch name when creating or renaming a branch, it must meet the following requirements:

  • Maximum length: 256 characters (API limit). Note that the Neon Console enforces a more restrictive limit of 128 characters.
  • Uniqueness: Branch names must be unique within a project. You cannot have two branches with the same name in the same project.
  • Non-empty: Branch names cannot be empty or consist only of whitespace characters.
  • Character flexibility: Unlike some other Neon resources (such as databases or roles), branch names have no special character restrictions. You can use any characters as long as they meet the requirements above.

Create a branch

To create a branch:

  1. In the Neon Console, select a project.
  2. Select Branches in the sidebar.
  3. Click New branch to open the branch creation dialog. Create branch dialog
  4. Select a Parent branch. This determines the origin of the schema and data for your new branch. By default, your project's default branch (named main if the project was created with the CLI or API, or production if created in the Console) is selected, but you can choose any existing branch in your project.
  5. Specify a branch name, or leave it blank to use the default generated name.
  6. Select what to include in the new branch:
    • Current data: Creates a copy of the parent branch’s latest data and schema, resulting in an isolated database that reflects the parent at the time of creation.
    • Past data: Creates a copy using data from a specific past date and time of the parent branch. The parent branch must have the relevant history.

      note

      You can only specify a date and time that falls within your history window.

    • Schema only: Replicates only the database schema (tables, views, roles, etc.) from the parent branch, without copying any of the actual data. This is useful for testing migrations or building new test data without exposing sensitive real-world data. See Schema-only branches.
    • Anonymized data: Creates a branch with masked sensitive data. You can configure data anonymization rules to protect personally identifiable information while preserving realistic data sets for development. See Data anonymization.
  7. Configure auto-deletion: By default, Automatically delete branch after is checked with 1 day selected to help prevent unused branches from accumulating. You can choose 1 hour, 1 day, or 7 days, or uncheck to disable expiration entirely. This is useful for CI/CD pipelines and short-lived development environments. Note: This default only applies when creating branches through the Console; API and CLI branches have no expiration by default. Refer to our Branch expiration guide for details.
  8. Click Create to create your branch.

You are presented with the connection details for your new branch and directed to the Branch overview page where you are shown the details for your new branch.

Postgres role passwords on branches

When creating a new branch, the branch will have the same Postgres roles and passwords as the parent branch. If you want your branch created with new role passwords, you can enable branch protection.

View branches

To view the branches in a Neon project:

  1. In the Neon Console, select a project.

  2. Select Branches in the sidebar to view all current branches in the project.

    all branches

    Branch details in this table view include:

    • Branch: The branch name, which is a generated name if no name was specified when created.
    • Parent: Indicates the parent from which this branch was created, helping you track your branch hierarchy.
    • Compute hours: Number of hours the branch's compute was active so far in the current billing period.
    • Primary compute: Shows the current compute size and status for the branch's compute.
    • Data size: Indicates the logical data size of the branch, helping you monitor your plan's storage limit. Data size does not include history.
    • Created by: The account or integration that created the branch.
    • Last active: Shows when the branch's compute was last active.
  3. Select a branch from the table to view details about the branch.

    Branch details shown on the branch page may include:

    • Archive status: This only appears if the branch was archived. For more, see Branch archiving.
    • ID: The branch ID. Branch IDs have a br- prefix.
    • Created on: The date and time the branch was created.
    • Compute hours: The compute hours used by the default branch in the current billing period.
    • Data size: The logical data size of the branch. Data size does not include history.
    • Parent branch: The branch from which this branch was created (only applicable to child branches).

    The branch details page also includes details about the Computes, Roles, Databases, and Child branches that belong to the branch. All of these objects are associated with a particular branch. For information about these objects, see:

Branch archiving

On the Free plan, Neon automatically archives inactive branches to cost-efficient archive storage after a defined threshold. For more, see Branch archiving.

note

For branches with predictable lifespans, you can set an expiration date when creating branches to automatically delete them at a specified time. This offers an alternative to archiving for temporary development and testing environments, ensuring cleanup happens exactly when needed.

Rename a branch

Neon permits renaming a branch, including your project's default branch.

To rename a branch:

  1. In the Neon Console, select a project.
  2. Select Branches in the sidebar to view the branches for the project.
  3. Select a branch from the table.
  4. On the branch overview page, open the three-dot menu (⋮) and select Rename.
  5. Specify a new name for the branch and click Save.

Set a branch as default

Each Neon project is created with a default branch (named main if the project was created with the CLI or API, or production if created in the Console), but you can designate any branch as your project's default branch. When creating a new branch without specifying the parent, a new branch is created from your project's default branch. Default branch is automatically selected in the UI when creating the new branch, and it's used in the create branch API call. The Neon-Managed Vercel integration also creates preview deployment branches from your project's default branch.

For more information, see Default branch.

To set a branch as the default branch:

  1. In the Neon Console, select a project.
  2. Select Branches in the sidebar to view the branches for the project.
  3. Select a branch from the table.
  4. On the branch overview page, open the three-dot menu (⋮) and select Set as default.
  5. In the Set as default confirmation dialog, click Set as default to confirm your selection.

Set a branch as protected

This feature is available on all Neon's paid plans, which supports up to five protected branches.

To set a branch as protected:

  1. In the Neon Console, select a project.
  2. Select Branches in the sidebar to view the branches for the project.
  3. Select a branch from the table.
  4. On the branch overview page, open the three-dot menu (⋮) and select Set as protected.
  5. In the Set as protected confirmation dialog, click Set as protected to confirm your selection.

For details and configuration instructions, refer to our Protected branches guide.

Set a branch expiration

To set or update a branch's expiration (auto-deletion TTL):

  1. In the Neon Console, select a project.
  2. Select Branches in the sidebar to view the branches for the project.
  3. Select a branch from the table.
  4. On the branch overview page, open the three-dot menu (⋮) and select Set expiration.
  5. Set a new expiration date and time, or toggle off "Automatically delete branch after" to remove expiration.
  6. Click Save.

For details and configuration instructions, refer to our Branch expiration guide.

Connect to a branch

You connect to a branch through a compute associated with it, using a Postgres connection string that carries your role, the compute hostname (it starts with ep-), and the database name. Get the string from the Console, CLI, or API, then connect with any Postgres client. To run queries without a client, use the Neon SQL Editor.

Click Connect in the Console nav, then select the branch, database, and role. Copy the connection string.

Connection details modal

Then connect with any client, for example psql:

psql postgresql://[user]:[password]@[neon_hostname]/[dbname]

For application connection examples, see Frameworks and Languages.

Reset a branch from parent

You can use Neon's Reset from parent feature to instantly update a branch with the latest schema and data from its parent. This feature can be an integral part of your CI/CD automation.

You can use the Neon Console, CLI, or API. For details, see Reset from parent.

Restore a branch to its own or another branch's history

There are several restore operations available using Neon's instant restore feature:

  • Restore a branch to its own history
  • Restore a branch to the head of another branch
  • Restore a branch to the history of another branch

You can use the Neon Console, CLI, or API. For more details, see Instant restore.

Delete a branch

Deleting a branch is a permanent action. Deleting a branch also deletes the databases and roles that belong to the branch as well as the compute associated with the branch. You cannot delete a branch that has child branches. The child branches must be deleted first.

To delete a branch:

  1. In the Neon Console, select a project.
  2. Select Branches in the sidebar.
  3. Select a branch from the table.
  4. On the branch overview page, open the three-dot menu (⋮) and select Delete.
  5. On the confirmation dialog, click Delete.

tip

For temporary branches, consider setting an expiration date when creating them to automate cleanup and reduce manual deletion overhead.

Check the data size

You can check the logical data size for the databases on a branch by viewing the Storage column on the Branches page in the Neon Console. Alternatively, you can run the following query on your branch from the Neon SQL Editor or any SQL client connected to your database:

SELECT pg_size_pretty(sum(pg_database_size(datname)))
FROM pg_database;

The query value may differ slightly from the Data size reported in the Neon Console.

Data size is your logical data size.

Storage is unlimited on paid plans

Storage is unlimited on paid plans (Launch and Scale): there's no hard per-branch size limit, and your branch storage grows with your usage. The Free plan is limited to 1 GB per project.

Branch types

Neon has different branch types with different characteristics.

Root branch

A root branch is a branch without a parent branch. Each Neon project starts with a root branch (named production in the Console, main via API/CLI), which cannot be deleted and is set as the default branch for the project.

Neon also supports two other types of root branches that have no parent but can be deleted:

The number of root branches allowed in a project depends on your Neon plan.

PlanRoot branch allowance per project
Free3
Launch5
Scale25

Default branch

Each Neon project has a default branch. In the Neon Console, your default branch is identified by a DEFAULT tag. You can designate any branch as the default branch for your project.

When creating a new branch without specifying the parent, a new branch is created from your project's default branch. The Neon-Managed Vercel integration also creates preview deployment branches from your project's default branch.

Non-default branch

Any branch not designated as the default branch is considered a non-default branch. You can rename or delete non-default branches.

Protected branch

Neon's protected branches feature implements a series of protections:

  • Protected branches cannot be deleted.
  • Protected branches cannot be reset.
  • Projects with protected branches cannot be deleted.
  • Computes associated with a protected branch cannot be deleted.
  • New passwords are automatically generated for Postgres roles on branches created from protected branches. Learn more.
  • With additional configuration steps, you can apply IP Allow restrictions to protected branches only. See How to apply IP restrictions to protected branches.
  • Protected branches are not archived due to inactivity.

Typically, a protected status is given to a branch or branches that hold production data or sensitive data. The protected branch feature is only supported on Neon's paid plans. See Set a branch as protected.

Schema-only branch

A branch that replicates only the database schema from a source branch, without copying any of the actual data. This feature is particularly valuable when working with sensitive information. Rather than creating branches that include confidential data, you can duplicate just the database structure and then populate it with your own data.

Schema-only branches are root branches, meaning they have no parent. As a root branch, each schema-only branch starts an independent line of data in a Neon project.

See Schema-only branches.

Backup branch

A branch created by an instant restore operation. When you restore a branch from a particular point in time, the current branch is saved as a backup branch. Performing a restore operation on a root branch, creates a backup branch without a parent branch (a root branch). See Instant restore.

Branch with expiration

A branch with an expiration timestamp is automatically deleted when the expiration time is reached. Any branch can have an expiration timestamp added or removed at any time. Use it for temporary development and testing environments.

Branching with the Neon CLI

The Neon CLI supports creating and managing branches. See Neon CLI commands — branches.

Branching with the Neon API

Branch actions performed in the Neon Console can also be performed using the Neon API. Each operation above includes an example in its API tab; see the Neon API Reference for complete request and response schemas. A request requires an API key: see Create an API key, where $NEON_API_KEY stands in for your key.

Create a branch with the API

See Create a branch for the Console, CLI, and API options.

List branches with the API

See View branches for the Console, CLI, and API options.

Delete a branch with the API

See Delete a branch for the Console, CLI, and API options.

Need help?

Join our Discord Server to ask questions or see what others are doing with Neon. For paid plan support options, see Support.

Last updated on

Was this page helpful?
Edit on GitHub