Run the following in your local repo or directly on GitHub:
git checkout main
git pull
git checkout -b staging
git push origin staging
This will serve as your staging environment and deploy context.
Create a GitHub Actions workflow to auto-update staging on every push to main.
Create a new workflow file at .github/workflows/sync-staging.yml:
name: Sync Main to Staging
on:
push:
branches:
- main
jobs:
sync:
runs-on: ubuntu-latest
steps:
- name: Checkout main
uses: actions/checkout@v3
with:
ref: main
fetch-depth: 0
- name: Configure Git
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
- name: Push to staging
run: |
git push origin main:staging --force
โ ๏ธ This force-pushes the contents of main into staging on every update. If you make direct edits on staging, they will be overwritten.
In Netlify Dashboard โ Site Settings โ Environment Variables, add under the branch-deploy context:
Key | Value |
---|---|
GATSBY_SANITY_DATASET | development |
โ Gatsby will now use the development dataset only when deploying the staging branch.
To allow Netlify to deploy the staging branch, follow these steps: