Guide
GitHub branching
Install the Layerbase GitHub App on a repository, map it to a database, and Layerbase keeps a staging database branch in sync with your git flow. When a pull request merges into your base branch, the staging branch is reset against production, so staging always mirrors what just shipped. The App install is its own grant, so it works no matter how you sign in to Layerbase, whether that is Google or GitHub.
How it works
A Layerbase database branch is a full, writable copy of its parent. Once branching is on, a branch is created in seconds, not by a slow byte copy, so it gets its own data almost immediately. You install the App once, map a repository, and Layerbase reacts to GitHub webhooks:
- Your base git branch (usually
main) is treated as production and uses your main database. - Your staging git branch uses a database branch forked from production.
- When a pull request merges into the base branch, the staging database branch is reset against production for you (if you opt in).
Branching runs on any Layerbase engine that supports it. See database branching for the current engine list.
Before you start
You need a database on Layerbase Cloud and a GitHub repository you can install an App on. Branching also has to be turned on for the database, which is a one-click toggle (next step).
1. Turn on Instant branches
Open the database on Layerbase Cloud, go to its Settings tab, and turn on Instant branches. New databases on branchable engines usually have it on already, in which case the setting simply reads Enabled. If it is off, turning it on prepares the database for branching: that takes a few minutes once, and the database is briefly unreachable while it runs. Your connection string stays the same either way.
2. Connect GitHub
Go to Integrations and click Connect GitHub. You will be sent to GitHub to install the Layerbase App, then returned to the dashboard. This is a repository install, independent of how you sign in, so a Google-login account connects it just the same. The connection is shared with your team, so any member can wire up a repository against it. Only the team owner can connect, add or remove GitHub accounts.
3. Install the App on your repos
On GitHub, choose the account or organization and pick the repositories to grant access to. You can select a single repo or all of them, and change the selection later with Manage next to the account on the Integrations page, or from GitHub Settings, then Installed GitHub Apps. The install brings its own webhooks, so there is no per-repo webhook to configure by hand.
Personal accounts and organizations
A team can connect several GitHub accounts at once: your personal account and any organizations you manage. Each one is listed on the Integrations page with its type. Click Add GitHub account or organization, then pick the other account on GitHub's install screen. Installing the App on an organization needs an owner of that organization. The repository pickers then list repositories from every connected account as owner/repo, and Layerbase always reads a repository through the account that owns it.
4. Create a mapping
Back in the dashboard, click New mapping and fill in:
- Database: the production database to fork from.
- Repository: one of the repos you installed the App on, from any connected account or organization.
- Base branch: your production git branch, read straight from the repo.
- Staging git branch and the name for the Layerbase staging branch to create.
- Reset staging on merge: re-fork staging from production when a PR merges to your base branch.
On Create mapping, Layerbase ensures the database is branchable and forks the staging branch. From then on, GitHub events drive the sync.
Reset staging on every merge (optional)
With Reset staging on merge on, Layerbase re-forks the staging branch from production whenever a pull request merges into your base branch. This keeps staging close to production, and is destructive: it discards whatever was in the staging branch. The connection string does not change, so nothing downstream needs re-wiring. It is off by default.
Permissions we ask for
The Layerbase GitHub App is deliberately read-only. It never gets write access to your repository, and it does not push code, open pull requests, or change any files.
- Contents: read-only, to list branches.
- Pull requests: read-only, to know when a PR merges.
- Metadata: read-only (required by every GitHub App).
The install subscribes to create, delete, push, pull_request, installation, and installation_repositories webhook events. Uninstalling or suspending the App on one account revokes that account's access immediately; your other connected accounts keep working.
What about environment variables?
Unlike the Vercel integration, GitHub has no deployment platform to inject a connection string into, so this integration does not set any environment variables. Your branch databases show up in the dashboard with their own connection strings, and CI or application code can resolve a branch by name through the branch API or the layerbase CLI. That keeps the credential in your own secret store rather than written back into GitHub.
Per-branch preview databases
Under Other feature branches, pick Branch per git branch and every new feature branch gets its own database branch, forked from production when the git branch is created. It is removed when the git branch is deleted. Turn on Delete a preview database when its pull request merges to remove it as soon as the pull request merges instead. A pull request closed without merging leaves its database branch in place until the git branch is deleted. Each preview branch counts toward your plan's branch limit.
Removing a mapping
Delete a mapping from the Integrations page. Your production database and the Layerbase staging branch are left untouched; delete the branch from its dashboard page if you want it gone. Mark any database or branch as persistent on its Settings tab to protect it from automated cleanup entirely. To stop using one GitHub account, click Remove next to it on the Integrations page: mappings on its repositories pause until you add the account again, and nothing is deleted. To disconnect GitHub entirely, also uninstall the App from that account on GitHub.