I have a Gatsby site on Gitlab deployed to Netlify and using Netlify-CMS. Netlify makes it possible to push the site to different branches and have each deployed to a separate url. For example my current site has a production
branch deployed to example.netlify.com
and a staging branch deployed to staging--example.netlify.com
.
However the commits created when updating content with Netlify CMS are a different matter. It appears that (out of the box at least), Netlify CMS will always push changes to a the production branch defined in its config, no matter which branch is checked out or where the site is located:
From docs.
Note: no matter where you access Netlify CMS — whether running locally, in a staging environment, or in your published site — it will always fetch and commit files in your hosted repository (for example, on GitHub), on the branch you configured in your Netlify CMS config.yml file. This means that content fetched in the admin UI will match the content in the repository, which may be different from your locally running site. It also means that content saved using the admin UI will save directly to the hosted repository, even if you're running the UI locally or in staging.
From the project config (config.yml
) used by Netlify CMS:
backend:
name: git-gateway
branch: production
So at the moment I can make changes to the fabric of the site and make them available only at staging, however there is no mechanism to make content changes and make them available only locally or only on staging.
One option I can see is to deploy a different config.yml
file to each deploy (and use a separate one locally), so when using the CMS locally I'd set the branch to dev
, and on staging and production I'd set the branch to staging
and production
respectively. Assuming the location of the content edited by Netlify-CMS is isolated, this should make it easy to promote content changes from staging
to production
.
Is this the best approach?