Branches

A copy of your project with its own database, keys and URL to try a change on, then merge its migrations into main.

A branch is a copy of your project to try a change on: a migration, a feature, a data fix. It has its own database, its own API keys and its own URL, <server>/b/<name>. When the change works, merge the branch's migrations into main. Data never moves between them.

shell
forkbase branch create dev                  # a copy of main's data
forkbase migration push --url http://127.0.0.1:8000/b/dev --service-key "$DEV_SERVICE_KEY"
forkbase branch merge dev --dry-run         # what would run on main
forkbase branch merge dev
forkbase branch delete dev --yes

Or on the dashboard: the branch switcher in the top bar, and Settings, Branches.

How a branch starts

fromThe branch's database
copy (default)main's data as it is now: tables, rows, users, buckets, functions, policies
migrationsan empty database, then main's app migrations applied in order
  • postgres mode: the copy is pg_dump of main restored into a new database fb_br_<name> on the same Postgres server, so the Postgres client tools are needed (see Backups); migrations needs only the database. The user in database.url must be allowed to create databases.
  • chronos mode: the copy is the engine's backup of main, opened by an engine of the branch's own.
  • Main's migrations are the ones in forkbase.app_migrations. Those pushed before 0.7 kept no SQL, so a migrations branch skips them and says so.

A copy is made safe before the branch first serves: main's signing keys, sessions, refresh tokens and MCP tokens are removed (the branch signs its own keys, so main's tokens are refused there and the branch's are refused on main), log drains and agents' webhooks are removed, job schedules are paused, and the branch gets an instance id of its own. Connections sealed with main's secret can't be opened on the branch: add the ones you need there again.

A branch keeps its stored files in its own data folder: a copy has main's buckets and file records, not the files.

Keys and access

Each branch writes its keys to <data>/branches/<name>/api-keys.json; admins read them at GET /platform/v1/branches/<name>/keys or in the branch's API keys menu. Apps use the branch URL and its anon key exactly as they use main's.

Through /b/<name>/..., this server's service key and a dashboard member's key are passed on as the branch's service key, after the member's role is checked against the path. Any other key goes through as it is, for the branch to check. Realtime's WebSocket is passed through the same way.

Merge

POST /platform/v1/branches/<name>/merge (forkbase branch merge) reads the branch's migrations and applies, in version order, each one main doesn't have, through main's own migrations API: each in a transaction, recorded on main.

  • A version on both with the same SQL is skipped (already_on_main).
  • A version on both with other SQL stops the merge with a 409: nothing after it runs.
  • {"dry_run": true} runs each on main and rolls it back.
  • main_only lists main's migrations the branch doesn't have: reset the branch to take them.
  • Each migration merged keeps where it came from: merged_from (the branch) and applied_by (who merged: a member's email, or service_role) in GET /platform/v1/migrations. The branch shows its last merge as merged_at and how many merges applied something as merges.

Reset and delete

POST /platform/v1/branches/<name>/reset {"confirm": true} stops the branch, makes its database again the way it was first made (a new copy, or main's migrations), and starts it. Its data and users are replaced, and its API keys change. DELETE /platform/v1/branches/<name> stops it and deletes its database, folder and keys. Main still remembers it: GET /platform/v1/branches lists it under deleted, with deleted_at and deleted_by (a member's email, or service key), when it was made and last merged. A name can be used again; each branch made is its own entry.

API

MethodPath
GET/platform/v1/branchesmain and every branch: name, from, status, url, created_at, created_by, merged_at, merges; deleted: branches deleted, newest first, with deleted_at and deleted_by too
POST/platform/v1/branches{"name": "dev", "from": "copy"} (branch_name works too)
GET/platform/v1/branches/<name>one branch, with merged_at and merges
DELETE/platform/v1/branches/<name>
POST/platform/v1/branches/<name>/reset{"confirm": true}
POST/platform/v1/branches/<name>/merge{"dry_run": false}
GET/platform/v1/branches/<name>/keysadmins: url, anon, service_role

Branches are made on the main server only, not inside a project or another branch. At most 50.

Something wrong or missing? Edit this page on GitHub or open an issue.

Branches · Forkbase