Working with branches
Learn how to develop and manage your Supabase branches
This guide covers how to work with Supabase branches effectively, including migration management, seeding behavior, and development workflows.
Subscribing to notifications
You can subscribe to webhook notifications when an action run completes on a persistent branch. The payload format follows the webhook standards.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849{ "type": "run.completed", "timestamp": "2025-10-17T02:27:18.705861793Z", "data": { "project_ref": "xuqpsshjxdecrwdyuxvs", "details_url": "https://supabase.com/dashboard/project/xuqpsshjxdecrwdyuxvs/branches", "action_run": { "id": "d5f8b4298d0a4d37b99e255c7837e7af", "created_at": "2025-10-17T02:27:10.133329324Z" "steps": [ { "name": "clone", "status": "exited", "updated_at": "2025-10-17T02:27:10.788435466Z" }, { "name": "pull", "status": "exited", "updated_at": "2025-10-17T02:27:11.701742857Z" }, { "name": "health", "status": "exited", "updated_at": "2025-10-17T02:27:12.79205717Z" }, { "name": "configure", "status": "exited", "updated_at": "2025-10-17T02:27:13.726839657Z" }, { "name": "migrate", "status": "exited", "updated_at": "2025-10-17T02:27:14.97017507Z" }, { "name": "seed", "status": "exited", "updated_at": "2025-10-17T02:27:15.637684921Z" }, { "name": "deploy", "status": "exited", "updated_at": "2025-10-17T02:27:18.604193114Z" } ] } }}We recommend registering a single webhooks processor that dispatches events to downstream services based on the payload type. The easiest way to do that is by deploying an Edge Function. For example, the following Edge Function listens for run completed events to notify a Slack channel.
supabase/functions/notify-slack/index.ts
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667// Setup type definitions for built-in Supabase Runtime APIsimport 'jsr:@supabase/functions-js/edge-runtime.d.ts'.('Branching notification booted!')const = ..('SLACK_WEBHOOK_URL') ?? ''.(async () => { const = await .() const = [ { : 'header', : { : 'plain_text', : `Action run ${... ? 'failed' : 'completed'}`, : true, }, }, { : 'section', : [ { : 'mrkdwn', : `*Branch ref:*\n${..}`, }, { : 'mrkdwn', : `*Run ID:*\n${...}`, }, ], }, { : 'section', : [ { : 'mrkdwn', : `*Started at:*\n${...}`, }, { : 'mrkdwn', : `*Completed at:*\n${.}`, }, ], }, { : 'section', : { : 'mrkdwn', : `<${..}|View logs>`, }, }, ] const = await (, { : 'POST', : .({ , }), }) const = await .() return new ( .({ , }), { : 200, } )})Setup Slack webhook URL
Create a Slack webhook URL and set it as Function secrets.
1supabase secrets set --project-ref <branch-ref> SLACK_WEBHOOK_URL=<your-webhook-url>Deploy your webhooks processor
Create and deploy an Edge Function to process webhooks.
1supabase functions deploy --project-ref <branch-ref> --use-api notify-slackUpdate branch notification URL
Update the notification URL of your target branch to point to your Edge Function.
1supabase branches update <branch-ref> --notify-url https://<branch-ref>.supabase.co/functions/v1/notify-slackAfter completing the steps above, you should receive a Slack message whenever an action run completes on your target branch.
Migration and seeding behavior
Migrations are run in sequential order. Each migration builds upon the previous one.
The preview branch has a record of which migrations have been applied, and only applies new migrations for each commit. This can create an issue when rolling back migrations.
Using ORM or custom seed scripts
If you want to use your own ORM for managing migrations and seed scripts, you will need to run them in GitHub Actions after the preview branch is ready. The branch credentials can be fetched using the following example GHA workflow.
.github/workflows/custom-orm.yaml
1234567891011121314151617181920212223242526272829303132333435363738394041name: Custom ORMon: pull_request: types: - opened - reopened - synchronize branches: - main paths: - 'supabase/**'jobs: wait: runs-on: ubuntu-latest outputs: status: ${{ steps.check.outputs.conclusion }} steps: - uses: fountainhead/action-wait-for-check@v1.2.0 id: check with: checkName: Supabase Preview ref: ${{ github.event.pull_request.head.sha || github.sha }} token: ${{ secrets.GITHUB_TOKEN }} migrate: needs: - wait if: ${{ needs.wait.outputs.status == 'success' }} runs-on: ubuntu-latest env: SUPABASE_ACCESS_TOKEN: ${{ secrets.SUPABASE_ACCESS_TOKEN }} SUPABASE_PROJECT_ID: ${{ secrets.SUPABASE_PROJECT_ID }} steps: - uses: supabase/setup-cli@v1 with: version: latest - run: supabase --experimental branches get "$GITHUB_HEAD_REF" -o env >> $GITHUB_ENV - name: Custom ORM migration run: psql "$POSTGRES_URL_NON_POOLING" -c 'select 1'Rolling back migrations
You might want to roll back changes you've made in an earlier migration change. For example, you may have pushed a migration file containing schema changes you no longer want.
To fix this, push the latest changes, then delete the preview branch in Supabase and reopen it.
The new preview branch is reseeded from the ./supabase/seed.sql file by default. Any additional data changes made on the old preview branch are lost. This is equivalent to running supabase db reset locally. All migrations are rerun in sequential order.
Seeding behavior
Your Preview Branches are seeded with sample data using the same as local seeding behavior.
The database is only seeded once, when the preview branch is created. To rerun seeding, delete the preview branch and recreate it by closing, and reopening your pull request.
Developing with branches
You can develop with branches using either local or remote development workflows.
Local development workflow
- Create a new Git branch for your feature
- Make schema changes using the Supabase CLI
- Generate migration files with
supabase db diff - Test your changes locally
- Commit and push to GitHub
- Open a pull request to create a preview branch
Remote development workflow
- Create a preview branch in the Supabase dashboard
- Switch to the branch using the branch dropdown
- Make schema changes in the dashboard
- Pull changes locally using
supabase db pull - Commit the generated migration files
- Push to your Git repository
Managing branch environments
Switching between branches
Use the branch dropdown in the Supabase dashboard to switch between different branches. Each branch has its own:
- Database instance
- API endpoints
- Authentication settings
- Storage buckets
Accessing branch credentials
Each branch has unique credentials that you can find in the dashboard:
- Switch to your desired branch
- Navigate to Settings > API
- Copy the branch-specific URLs and keys
Branch isolation
Branches are completely isolated from each other. Changes made in one branch don't affect others, including:
- Database schema and data
- Storage objects
- Edge Functions
- Auth configurations
Next steps
- Learn about branch configuration
- Explore integrations
- Review troubleshooting guide