--- title: Manage branches enableTableOfContents: true isDraft: false redirectFrom: - /docs/get-started/get-started-branching updatedOn: '2025-10-24T21:38:50.621Z' --- Data resides in a branch. Each Neon project is created with a [root branch](#root-branch) called `production`, which is also designated as your [default branch](#default-branch). You can create child branches from `production` or from previously created branches. A branch can contain multiple databases and roles. Neon's [plan allowances](/docs/introduction/plans) 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](/docs/introduction/branching). You can create and manage branches using the Neon Console, [Neon CLI](/docs/reference/neon-cli), or [Neon API](https://api-docs.neon.tech/reference/getting-started-with-neon-api). 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 [restore window](/docs/introduction/branching#restore-window). ## Create a branch To create a branch: 1. In the Neon Console, select a project. 2. Select **Branches**. 3. Click **New branch** to open the branch creation dialog. 4. Specify a branch name. 5. Select a **branch setup** option. If you're interested in schema-only branches, see [Schema-only branches](/docs/guides/branching-schema-only). When creating a branch with past data, you can only specify a date and time that falls within your [restore window](/docs/manage/projects#configure-restore-window). 6. Optionally set an **Expire branch after** expiration date and time for temporary branches. This automatically deletes the branch at the specified time, useful for CI/CD pipelines and short-lived development environments. Refer to our [Branch expiration guide](/docs/guides/branch-expiration) for details. 7. Click **Create new 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. 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](/docs/guides/protected-branches). ## View branches To view the branches in a Neon project: 1. In the Neon Console, select a project. 1. Select **Branches** to view all current branches in the project. ![all branches](/docs/manage/branches_all_list.png) 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. 1. 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](/docs/guides/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: - [Manage computes](/docs/manage/computes#view-a-compute). - [Manage roles](/docs/manage/roles) - [Manage databases](/docs/manage/databases) - [View branches](#view-branches) ## 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](/docs/guides/branch-archiving). 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** to view the branches for the project. 3. Select a branch from the table. 4. On the branch overview page, click the **More** drop-down 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 called `production`, but you can designate any branch as your project's default branch. The default branch serves two key purposes: - For users on paid plans, the compute associated with the default branch is exempt from the [concurrently active compute limit](/docs/reference/glossary#concurrently-active-compute-limit), ensuring that it is always available. - The [Neon-Managed Vercel integration](/docs/guides/neon-managed-vercel-integration) creates preview deployment branches from your Neon project's default branch. For more information, see [Default branch](#default-branch). To set a branch as the default branch: 1. In the Neon Console, select a project. 2. Select **Branches** to view the branches for the project. 3. Select a branch from the table. 4. On the branch overview page, click the **More** drop-down 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** to view the branches for the project. 3. Select a branch from the table. 4. On the branch overview page, click the **More** drop-down 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](/docs/guides/protected-branches). ## 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** to view the branches for the project. 3. Select a branch from the table. 4. On the branch overview page, click the **Actions** drop-down menu and select **Edit expiration**. 5. Set a new expiration date and time, or toggle off "Expire branch after" to remove expiration. 6. Click **Save**. For details and configuration instructions, refer to our [Branch expiration guide](/docs/guides/branch-expiration). ## Connect to a branch Connecting to a database in a branch requires connecting via a compute associated with the branch. The following steps describe how to connect using `psql` and a connection string obtained from the Neon Console. You can also query the databases in a branch from the Neon SQL Editor. For instructions, see [Query with Neon's SQL Editor](/docs/get-started/query-with-neon-sql-editor). 1. In the Neon Console, select a project. 2. Find the connection string for your database by clicking the **Connect** button on your **Project Dashboard**. Select the branch, the database, and the role you want to connect with. ![Connection details modal](/docs/connect/connection_details.png) 3. Copy the connection string. A connection string includes your role name, the compute hostname, and database name. 4. Connect with `psql` as shown below. ```bash shouldWrap psql postgresql://[user]:[password]@[neon_hostname]/[dbname] ``` A compute hostname starts with an `ep-` prefix. You can also find a compute hostname on the **Branches** page in the Neon Console. See [View branches](#view-branches). If you want to connect from an application, the **Connect to your database modal**, accessed by clicking **Connect** on the project **Dashboard**, and the [Frameworks](/docs/get-started/frameworks) and [Languages](/docs/get-started/languages) sections in the documentation provide various connection examples. ## 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](/docs/guides/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](/docs/guides/branch-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**. 3. Select a branch from the table. 4. On the branch overview page, click the **More** drop-down menu and select **Delete**. 5. On the confirmation dialog, click **Delete**. 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 **Data size** value on the **Branches** page or page in the Neon Console. Alternatively, you can run the following query on your branch from the [Neon SQL Editor](/docs/get-started/query-with-neon-sql-editor) or any SQL client connected to your database: ```sql 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. ## 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`, which cannot be deleted and is set as the [default branch](#default-branch) for the project. Neon also supports two other types of root branches that have no parent but _can_ be deleted: - [Backup branches](#backup-branch), created by instant restore operations on other root branches. - [Schema-only branches](#schema-only-branch). The number of root branches allowed in a project depends on your Neon plan. | Plan | Root branch allowance per project | | :----- | :-------------------------------- | | Free | 3 | | Launch | 5 | | Scale | 25 | ### 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. The default branch serves two key purposes: - For users on paid plans, the compute associated with the default branch is exempt from the [concurrently active compute limit](/docs/reference/glossary#concurrently-active-compute-limit), ensuring that it is always available. - The [Neon-Managed Vercel integration](/docs/guides/neon-managed-vercel-integration) creates preview deployment branches from your Neon 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. - For Neon Free plan users, computes associated with **non-default branches** are suspended if you exceed the Neon Free plan 5 hours per month for **non-default branches**. - For users on paid plans, default limits prevent more than 20 concurrently active computes. Beyond that limit, additional computes will remain suspended. ### Protected branch Neon's protected branches feature implements a series of protections: - Protected branches cannot be deleted. - Protected branches cannot be [reset](/docs/manage/branches#reset-a-branch-from-parent). - 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. [See below](#new-passwords-generated-for-postgres-roles-on-child-branches). - With additional configuration steps, you can apply IP Allow restrictions to protected branches only. See [below](#how-to-apply-ip-restrictions-to-protected-branches). - Protected branches are not [archived](/docs/guides/branch-archiving) 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](#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](#root-branch), 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](/docs/guides/branching-schema-only). ### Backup branch A branch created by an [instant restore](#branch-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](/docs/guides/branch-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. This feature is particularly useful for temporary development and testing environments. ## Branching with the Neon CLI The Neon CLI supports creating and managing branches. For instructions, see [Neon CLI commands — branches](/docs/reference/cli-branches). For a Neon CLI branching guide, see [Branching with the Neon CLI](/docs/reference/cli-branches). ## Branching with the Neon API Branch actions performed in the Neon Console can also be performed using the Neon API. The following examples demonstrate how to create, view, and delete branches using the Neon API. For other branch-related API methods, refer to the [Neon API reference](https://api-docs.neon.tech/reference/getting-started-with-neon-api). The API examples that follow may not show all of the user-configurable request body attributes that are available to you. To view all of the attributes for a particular method, refer to the method's request body schema in the [Neon API reference](https://api-docs.neon.tech/reference/getting-started-with-neon-api). The `jq` option specified in each example is an optional third-party tool that formats the `JSON` response, making it easier to read. For information about this utility, see [jq](https://stedolan.github.io/jq/). ### Prerequisites A Neon API request requires an API key. For information about obtaining an API key, see [Create an API key](/docs/manage/api-keys#create-an-api-key). In the examples shown below, `$NEON_API_KEY` is specified in place of an actual API key, which you must provide when making a Neon API request. ### Create a branch with the API The following Neon API method creates a branch. To view the API documentation for this method, refer to the [Neon API reference](https://api-docs.neon.tech/reference/createprojectbranch). ```http POST /projects/{project_id}/branches ``` The API method appears as follows when specified in a cURL command. The `endpoints` attribute creates a compute, which is required to connect to the branch. A branch can be created with or without a compute. The `branch` attribute specifies the parent branch. This method does not require a request body. Without a request body, the method creates a branch from the project's default branch, and a compute is not created. ```bash curl 'https://console.neon.tech/api/v2/projects/dry-heart-13671059/branches' \ -H 'Accept: application/json' \ -H "Authorization: Bearer $NEON_API_KEY" \ -H 'Content-Type: application/json' \ -d '{ "endpoints": [ { "type": "read_write" } ], "branch": { "parent_id": "br-wispy-dew-591433" } }' | jq ``` - The `project_id` for a Neon project is found on the **Settings** page in the Neon Console, or you can find it by listing the projects for your Neon account using the Neon API. - The `parent_id` can be obtained by listing the branches for your project. See [List branches](#list-branches-with-the-api). The `` is the `id` of the branch you are branching from. A branch `id` has a `br-` prefix. You can branch from your Neon project's default branch or a previously created branch. The response body includes information about the branch, the branch's compute, and the `create_branch` and `start_compute` operations that were initiated.
Response body For attribute definitions, find the [Create branch](https://api-docs.neon.tech/reference/createprojectbranch) endpoint in the [Neon API Reference](https://api-docs.neon.tech/reference/getting-started-with-neon-api). Definitions are provided in the **Responses** section. ```json { "branch": { "id": "br-curly-wave-af4i4oeu", "project_id": "dry-heart-13671059", "parent_id": "br-morning-meadow-afu2s1jl", "parent_lsn": "0/1FA22C0", "name": "br-curly-wave-af4i4oeu", "current_state": "init", "pending_state": "ready", "state_changed_at": "2025-08-04T07:13:09Z", "creation_source": "console", "primary": false, "default": false, "protected": false, "cpu_used_sec": 0, "compute_time_seconds": 0, "active_time_seconds": 0, "written_data_bytes": 0, "data_transfer_bytes": 0, "created_at": "2025-08-04T07:13:09Z", "updated_at": "2025-08-04T07:13:09Z", "created_by": { "name": "your@email.com", "image": "" }, "init_source": "parent-data" }, "endpoints": [ { "host": "ep-cool-darkness-123456.c-2.us-west-2.aws.neon.tech", "id": "ep-cool-darkness-123456", "project_id": "dry-heart-13671059", "branch_id": "br-curly-wave-af4i4oeu", "autoscaling_limit_min_cu": 0.25, "autoscaling_limit_max_cu": 0.25, "region_id": "aws-us-west-2", "type": "read_write", "current_state": "init", "pending_state": "active", "settings": {}, "pooler_enabled": false, "pooler_mode": "transaction", "disabled": false, "passwordless_access": true, "creation_source": "console", "created_at": "2025-08-04T07:13:09Z", "updated_at": "2025-08-04T07:13:09Z", "proxy_host": "c-2.us-west-2.aws.neon.tech", "suspend_timeout_seconds": 0, "provisioner": "k8s-neonvm" } ], "operations": [ { "id": "8289b00a-4341-48d2-b3f1-d0c8dbb7e806", "project_id": "dry-heart-13671059", "branch_id": "br-curly-wave-af4i4oeu", "action": "create_branch", "status": "running", "failures_count": 0, "created_at": "2025-08-04T07:13:09Z", "updated_at": "2025-08-04T07:13:09Z", "total_duration_ms": 0 }, { "id": "a3c9baa4-6732-4774-a141-9d03396babce", "project_id": "dry-heart-13671059", "branch_id": "br-curly-wave-af4i4oeu", "endpoint_id": "ep-cool-darkness-123456", "action": "start_compute", "status": "scheduling", "failures_count": 0, "created_at": "2025-08-04T07:13:09Z", "updated_at": "2025-08-04T07:13:09Z", "total_duration_ms": 0 } ], "roles": [ { "branch_id": "br-curly-wave-af4i4oeu", "name": "alex", "protected": false, "created_at": "2025-08-04T07:07:55Z", "updated_at": "2025-08-04T07:07:55Z" } ], "databases": [ { "id": 2886327, "branch_id": "br-curly-wave-af4i4oeu", "name": "dbname", "owner_name": "alex", "created_at": "2025-08-04T07:07:55Z", "updated_at": "2025-08-04T07:07:55Z" } ], "connection_uris": [ { "connection_uri": "postgresql://alex:AbC123dEf@ep-cool-darkness-123456.c-2.us-west-2.aws.neon.tech/dbname?sslmode=require&channel_binding=require", "connection_parameters": { "database": "dbname", "password": "AbC123dEf", "role": "alex", "host": "ep-cool-darkness-123456.c-2.us-west-2.aws.neon.tech", "pooler_host": "ep-cool-darkness-123456-pooler.c-2.us-west-2.aws.neon.tech" } } ] } ```
### List branches with the API The following Neon API method lists branches for the specified project. To view the API documentation for this method, refer to the [Neon API reference](https://api-docs.neon.tech/reference/listprojectbranches). ```http GET /projects/{project_id}/branches ``` The API method appears as follows when specified in a cURL command: ```bash curl 'https://console.neon.tech/api/v2/projects/dry-heart-13671059/branches' \ -H 'accept: application/json' \ -H "Authorization: Bearer $NEON_API_KEY" | jq ``` The `project_id` for a Neon project is found on the **Settings** page in the Neon Console, or you can find it by listing the projects for your Neon account using the Neon API. The response body lists the project's default branch and any child branches. The name of the default branch in this example is `main`.
Response body For attribute definitions, find the [List branches](https://api-docs.neon.tech/reference/listprojectbranches) endpoint in the [Neon API Reference](https://api-docs.neon.tech/reference/getting-started-with-neon-api). Definitions are provided in the **Responses** section. ```json { "branches": [ { "id": "br-curly-wave-af4i4oeu", "project_id": "dry-heart-13671059", "parent_id": "br-morning-meadow-afu2s1jl", "parent_lsn": "0/1FA22C0", "parent_timestamp": "2025-08-04T07:08:48Z", "name": "br-curly-wave-af4i4oeu", "current_state": "ready", "state_changed_at": "2025-08-04T07:13:09Z", "creation_source": "console", "primary": false, "default": false, "protected": false, "cpu_used_sec": 0, "compute_time_seconds": 0, "active_time_seconds": 0, "written_data_bytes": 0, "data_transfer_bytes": 0, "created_at": "2025-08-04T07:13:09Z", "updated_at": "2025-08-04T07:18:15Z", "created_by": { "name": "your@email.com", "image": "" }, "init_source": "parent-data" }, { "id": "br-morning-meadow-afu2s1jl", "project_id": "dry-heart-13671059", "name": "main", "current_state": "ready", "state_changed_at": "2025-08-04T07:07:58Z", "logical_size": 30777344, "creation_source": "console", "primary": true, "default": true, "protected": false, "cpu_used_sec": 0, "compute_time_seconds": 0, "active_time_seconds": 0, "written_data_bytes": 0, "data_transfer_bytes": 0, "created_at": "2025-08-04T07:07:55Z", "updated_at": "2025-08-04T07:13:11Z", "created_by": { "name": "your@email.com", "image": "" }, "init_source": "parent-data" } ], "annotations": {}, "pagination": { "sort_by": "updated_at", "sort_order": "DESC" } } ```
### Delete a branch with the API The following Neon API method deletes the specified branch. To view the API documentation for this method, refer to the [Neon API reference](https://api-docs.neon.tech/reference/deleteprojectbranch). ```http DELETE /projects/{project_id}/branches/{branch_id} ``` The API method appears as follows when specified in a cURL command: ```bash curl -X 'DELETE' \ 'https://console.neon.tech/api/v2/projects/dry-heart-13671059/branches/br-curly-wave-af4i4oeu' \ -H 'accept: application/json' \ -H "Authorization: Bearer $NEON_API_KEY" | jq ``` - The `project_id` for a Neon project is found on the **Settings** page in the Neon Console, or you can find it by listing the projects for your Neon account using the Neon API. - The `branch_id` can be found by listing the branches for your project. The `` is the `id` of a branch. A branch `id` has a `br-` prefix. See [List branches](#list-branches-with-the-api). The response body shows information about the branch being deleted and the `suspend_compute` and `delete_timeline` operations that were initiated.
Response body For attribute definitions, find the [Delete branches](https://api-docs.neon.tech/reference/deleteprojectbranch) endpoint in the [Neon API Reference](https://api-docs.neon.tech/reference/getting-started-with-neon-api). Definitions are provided in the **Responses** section. ```json { "branch": { "id": "br-curly-wave-af4i4oeu", "project_id": "dry-heart-13671059", "parent_id": "br-morning-meadow-afu2s1jl", "parent_lsn": "0/1FA22C0", "parent_timestamp": "2025-08-04T07:08:48Z", "name": "br-curly-wave-af4i4oeu", "current_state": "ready", "pending_state": "storage_deleted", "state_changed_at": "2025-08-04T07:13:09Z", "logical_size": 30851072, "creation_source": "console", "primary": false, "default": false, "protected": false, "cpu_used_sec": 0, "compute_time_seconds": 0, "active_time_seconds": 0, "written_data_bytes": 0, "data_transfer_bytes": 0, "created_at": "2025-08-04T07:13:09Z", "updated_at": "2025-08-04T07:21:55Z", "created_by": { "name": "your@email.com", "image": "" }, "init_source": "parent-data" }, "operations": [ { "id": "eb85073d-53fc-4d37-a32a-ca9e9ea1eeb1", "project_id": "dry-heart-13671059", "branch_id": "br-curly-wave-af4i4oeu", "endpoint_id": "ep-soft-art-af5jvg5j", "action": "suspend_compute", "status": "running", "failures_count": 0, "created_at": "2025-08-04T07:21:55Z", "updated_at": "2025-08-04T07:21:55Z", "total_duration_ms": 0 }, { "id": "586af342-1ffe-4e0a-9e11-326db1164ad7", "project_id": "dry-heart-13671059", "branch_id": "br-curly-wave-af4i4oeu", "action": "delete_timeline", "status": "scheduling", "failures_count": 0, "created_at": "2025-08-04T07:21:55Z", "updated_at": "2025-08-04T07:21:55Z", "total_duration_ms": 0 } ] } ```
You can verify that a branch is deleted by listing the branches for your project. See [List branches](#list-branches-with-the-api). The deleted branch should no longer be listed.