Neon CLI commands — branches
Use the Neon CLI to manage Neon directly from the terminal
Before you begin
- Before running the
branches
command, ensure that you have installed the Neon CLI. - If you have not authenticated with the neonctl auth command, running a Neon CLI command automatically launches the Neon CLI browser authentication process. Alternatively, you can specify a Neon API key using the
--api-key
option when running a command. See Connect.
branches
command
The The branches
command allows you to list, create, rename, delete, and retrieve information about branches in your Neon project. It also permits setting a branch as the primary branch and adding a compute endpoint to a branch. You can create a read replica by adding a read-only compute endpoint.
Usage
Subcommand | Description |
---|---|
list | List branches |
create | Create a branch |
reset | Reset data to parent |
rename | Rename a branch |
set-primary | Set a primary branch |
add-compute | Add replica to a branch |
delete | Delete a branch |
get | Get a branch |
list
This subcommand allows you to list branches in a Neon project.
Usage
Options
In addition to the Neon CLI global options, the list
subcommand supports these options:
Option | Description | Type | Required |
---|---|---|---|
--context-file | Context file path and file name | string | |
--project-id | Project ID | string | Only if your Neon account has more than one project |
Examples
-
List branches with the default
table
output format. The information provided with this output format is limited compared to other formats, such asjson
. -
List branches with the
json
output format. This format provides more information than the defaulttable
output format.
create
This subcommand allows you to create a branch in a Neon project.
Usage
Options
In addition to the Neon CLI global options, the create
subcommand supports these options:
Option | Description | Type | Required |
---|---|---|---|
--context-file | Context file path and file name | string | |
--project-id | Project ID | string | Only if your Neon account has more than one project |
--name | The branch name | string | |
--parent | Parent branch name, id, timestamp, or LSN. Defaults to the primary branch | string | |
--compute | Create a branch with or without a compute. By default, the branch is created with a read-write endpoint. The default value is true . To create a branch without a compute, use --no-compute | boolean | |
--type | Type of compute to add. Choices are read_write (the default) or read_only . A branch with a read-only compute endpoint is also referred to as a read replica. | string | |
--suspend-timeout | Duration of inactivity in seconds after which the compute endpoint is automatically suspended. The value 0 means use the global default. The value -1 means never suspend. The default value is 300 seconds (5 minutes). The maximum value is 604800 seconds (1 week). | number | |
--psql | Connect to a new branch via psql . psql must be installed to use this option. | boolean |
Examples
-
Create a branch:
tip
The Neon CLI provides a
neonctl connection-string
command you can use to extract a connection uri programmatically. See Neon CLI commands — connection-string. -
Create a branch with the
--output
format of the command set tojson
. This output format returns all of the branch response data, whereas the defaulttable
output format (shown in the preceding example) is limited in the information it can display.Example output
-
Create a branch with a user-defined name:
-
Create a branch with a read-only compute endpoint (a read replica)
-
Create a branch from a parent branch other than your
main
branch -
Create a point-in-time restore branch by specifying the
--parent
option with a timestamp:The timestamp must be provided in ISO 8601 format. You can use this timestamp converter. For more information about point-in-time restore, see Branching — Point-in-time restore (PITR).
-
Create a branch and connect to it with
psql
. -
Create a branch, connect to it with
psql
, and run an.sql
file. -
Create a branch, connect to it with
psql
, and run a query.
reset
This command resets a child branch to the latest data from its parent.
Usage
<id|name>
refers to the branch ID or branch name. You can use either one for this operation.
--parent
specifies the type of reset operation. Currently, Neon only supports reset from parent. This parameter is required for the operation to work. In the future, Neon might add support for other reset types: for example, rewinding a branch to an earlier period in time.
Options
In addition to the Neon CLI global options, the reset
subcommand supports these options:
Option | Description | Type | Required |
---|---|---|---|
--context-file | Context file path and file name | string | |
--project-id | Project ID | string | Only if your Neon account has more than one project or context is not set |
--parent | Reset to a parent branch | boolean | |
--preserve-under-name | The name under which to preserve the old branch | string |
Example
rename
This subcommand allows you to update a branch in a Neon project.
Usage
<id|name>
refers to the Branch ID and branch name. You can specify one or the other.
Options
In addition to the Neon CLI global options, the rename
subcommand supports these options:
Option | Description | Type | Required |
---|---|---|---|
--context-file | Context file path and file name | string | |
--project-id | Project ID | string | Only if your Neon account has more than one project |
Example
set-primary
This subcommand allows you to set a branch as the primary branch in your Neon project.
Usage
<id|name>
refers to the Branch ID and branch name. You can specify one or the other.
Options
In addition to the Neon CLI global options, the set-primary
subcommand supports this option:
Option | Description | Type | Required |
---|---|---|---|
--context-file | Context file path and file name | string | |
--project-id | Project ID | string | Only if your Neon account has more than one project |
Example
add-compute
This subcommand allows you to add a compute endpoint to an existing branch in your Neon project.
Usage
<id|name>
refers to the Branch ID and branch name. You can specify one or the other.
Options
In addition to the Neon CLI global options, the add-compute
subcommand supports these options:
Option | Description | Type | Required |
---|---|---|---|
--context-file | Context file path and file name | string | |
--project-id | Project ID | string | Only if your Neon account has more than one project |
--type | Type of compute to add. Choices are read_only (the default) or read_write . A branch with a read-only compute endpoint is also referred to as a read replica. A branch can have a single read-write and multiple read-only compute endpoints. | string |
Example
delete
This subcommand allows you to delete a branch in a Neon project.
Usage
<id|name>
refers to the Branch ID and branch name. You can specify one or the other.
Options
In addition to the Neon CLI global options, the delete
subcommand supports this option:
Option | Description | Type | Required |
---|---|---|---|
--context-file | Context file path and file name | string | |
--project-id | Project ID | string | Only if your Neon account has more than one project |
Example
get
This subcommand allows you to retrieve details about a branch.
Usage
Options
In addition to the Neon CLI global options, the get
subcommand supports this option:
Options
Option | Description | Type | Required |
---|---|---|---|
--context-file | Context file path and file name | string | |
--project-id | Project ID | string | Only if your Neon account has more than one project |
Examples
A get
example with the --output
format option set to json
:
Need help?
Join our Discord Server to ask questions or see what others are doing with Neon. Neon Pro Plan users can open a support ticket from the console. For more detail, see Getting Support.
Last updated on