Reputation: 5021
I want to use Github Pages to publish a production website (at, say, www.example.com) and also a staging version of the same site (at, say, staging.example.com).
I've set up a repo (e.g. my-jekyll-website) in Github for the production site, created a gh-pages branch, and set the CNAME file in the root level of the repo to www.example.com. Works great.
Now, what's the least painful way to also be able to push changes to staging.example.com?
One thing I've tried is setting up a second remote repo on Github (e.g. my-jekyll-website-staging), then adding this as a remote to my local git config. Works great, except that the CNAME file in the repo needs to be changed to staging.example.com for this to work. Which is no good, because then when I want to deploy to production, I'd need to change the CNAME file back to www.example.com. Not ideal.
I've looked at using git filter content drivers, but if I understand correctly, that's about modifying files locally, not getting different versions of a file pushed to different remotes.
Edit: I've also considered not using a custom domain for staging at all: i.e., just using username.github.io/my-jekyll-website-staging. Unfortunately, then my site-root-relative links (e.g. /images/foo.bar) break, because the baseurl is now different between production and staging.
Upvotes: 21
Views: 6876
Reputation: 1
If you deploy using a GitHub Actions workflow, I believe you don't need CNAME files. See this: GitHub Pages documentation
If you are publishing from a custom GitHub Actions workflow, any CNAME file is ignored and is not required.
You just need to make sure that the URLs are correctly configured in the GitHub Pages settings of the repositories.
I spent an afternoon attempting to bypass the CNAME push for deployments from staging to production. Eventually, I discovered that removing the CNAME files while deploying through GitHub Actions resolves the issue effectively.
Upvotes: 0
Reputation: 325
I know that's an old post, but i've got tons of SO tabs open searching for a similar solution. None offered something I liked, so i ended up doing something else.
I'm using Hostinger VPS, and it has an option of Git deployment & Git web hooks. Create a GitHub Action workflow, and add a step to fire a curl
command to Hostinger's web hook URL
Upvotes: 0
Reputation: 836
Pulled from comments above:
[M]erge the staging git branch into the production branch and push[.] You could just keep the CNAMEs permanently pointing to their respective repos, but manipulate the repos separately.
Comment originally by Jonathan Chan
Do as @JonathanChan says: maintain two separate branches, then hijack your CNAME file in each one. This way local changes (to the CNAME) will not be committed to the repository.
Upvotes: 6