Skip to content

PlanetScale CLI commands: branch

Use the PlanetScale CLI “branch” command to create, delete, diff, and manage branches from your terminal.

Getting Started

Make sure to first set up your PlanetScale developer environment. Once you've installed the pscale CLI, you can interact with PlanetScale and manage your databases straight from the command line.

The branch command

This command allows you to create, delete, diff, and manage branches.

Usage:

Terminal
pscale branch <SUB-COMMAND> <FLAG>

Available sub-commands

Sub-commandSub-command flagsDescription
create <DATABASE_NAME> <BRANCH_NAME>--from <SOURCE_BRANCH>, --region <BRANCH_REGION>, --restore <BACKUP_NAME>, --seed-data, --waitCreate a new branch on the specified database
delete <DATABASE_NAME> <BRANCH_NAME>--forceDelete the specified branch from the a database
diff <DATABASE_NAME> <BRANCH_NAME>--webShow the diff of the specified branch against the parent branch.
keyspaces <DATABASE_NAME> <BRANCH_NAME>Show information for sharded keyspaces.
list <DATABASE_NAME>--webList all branches of a database
promote <DATABASE_NAME> <BRANCH_NAME>Promote a database branch to production
refresh-schema <DATABASE_NAME> <BRANCH_NAME>Refresh the schema for a database branch
safe-migrations enable <DATABASE_NAME> <BRANCH_NAME>Enables safe migrations for a database branch
safe-migrations disable <DATABASE_NAME> <BRANCH_NAME>Disables safe migrations for a database branch
schema <DATABASE_NAME> <BRANCH_NAME>--webShow the schema of a branch
show <DATABASE_NAME> <BRANCH_NAME>--webShow a specific backup of a branch
switch <BRANCH_NAME> --database <DATABASE_NAME>--database <DATABASE_NAME>*, --create, parent-branch <BRANCH_NAME>Switch to the specified branch
vschema <DATABASE_NAME> <BRANCH_NAME>Show the vschema for a sharded keyspace. Empty on non-sharded keyspaces.

* Flag is required

Sub-command flag descriptions

Some of the sub-commands have additional flags unique to the sub-command. This section covers what each of those does. See the above table for which context.

Sub-command flagDescriptionApplicable sub-commands
--from <SOURCE_BRANCH>Parent branch that you want to create a new branch off ofcreate
--region <BRANCH_REGION>Region where database should be createdcreate
--restore <BACKUP_NAME>Create a new branch from a specified backupcreate
--seed-dataCreate a new branch and seed data using the Data Branching® featurecreate
--webPerform the action in your web browsercreate, diff, list, schema, show
--waitWait until the branch is readycreate
--database <DATABASE_NAME>Specify the database nameswitch
--createCreate a new branch if it does not existswitch
--parent-branch <BRANCH_NAME>If a new branch is being created, use this to specify a parent branch. Default is main.switch

Available flags

FlagDescription
-h, --helpView help for auth command
--org <ORGANIZATION_NAME>The organization for the current user

Global flags

CommandDescription
--api-token <TOKEN>The API token to use for authenticating against the PlanetScale API.
--api-url <URL>The base URL for the PlanetScale API. Default is https://api.planetscale.com/.
--config <CONFIG_FILE>Config file. Default is $HOME/.config/planetscale/pscale.yml.
--debugEnable debug mode.
-f, --format <FORMAT>Show output in a specific format. Possible values: human (default), json, csv.
--no-colorDisable color output.
--service-token <TOKEN>The service token for authenticating.
--service-token-id <TOKEN_ID>The service token ID for authenticating.

Examples

The list sub-command with --web flag

Command:

Terminal
pscale branch list <DATABASE_NAME> --web

Output:

Opens the Branches page, <https://app.planetscale.com/org/database/branches>, in browser.

The diff sub-command

Command:

Terminal
pscale branch diff <DATABASE_NAME> <BRANCH_NAME>

Output:

-- users --
+CREATE TABLE `users` (
+ `id` bigint unsigned NOT NULL AUTO_INCREMENT,
+ `name` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
+ PRIMARY KEY (`id`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

This will return the diff against the parent branch.

Need help?

Get help from the PlanetScale support team, or join our GitHub discussion board to see how others are using PlanetScale.

Was this page useful?
Last updated on Help us improve this page