Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GitHub Pages Custom Domain Settings Gets Reset During new Commit

I have a static site generated using Zola and I'm using GitHub Actions to do a build of my static site and publish that into a gh-pages branch of my repository. I have also configured my project to serve via GitHub pages using the gh-pages branch.

The problem I'm facing is that as soon as my GitHub action builds a new version and pushes it to the gh-pages branch, the custom domain setting in the GitHub settings gets reset.

Here is what I do in my GitHub action to build and push to TARGET_BRANCH (gh-pages) branch:

  - name: Commit and push to target branch
    run: |-
      git config --global user.email "[email protected]"
      git config --global user.name "workflow-bot"
      git checkout --orphan $TARGET_BRANCH
      rm -rf .github/
      mv public ..
      rm -rf *
      mv ../public/* .
      touch .nojekyll
      touch README.md
      echo 'https://www.bigelectrons.com - SITE GENERATED USING ZOLA' > README.md
      git add .
      git commit -m "generated using zola build"
      git push --set-upstream origin $TARGET_BRANCH --force

Any idea what the problem is and how I could resolve th

like image 985
joesan Avatar asked Jul 27 '26 07:07

joesan


2 Answers

I just had to add a CNAME file to my gh-pages branch. For example., in the run command, I had to add these two lines:

touch CNAME
echo 'mydomain.com' > CNAME
like image 125
joesan Avatar answered Jul 29 '26 09:07

joesan


I know this is not Zola-related, but I've stumbled upon the same error when using Mkdocs. The documentation says that you need to create a CNAME file in your docs_dir directory, so that their gh-deploy script can pick that up and copy it at the right place in the gh-pages branch (see that doc here).

For information, using the Github developer settings page to set the custom domain does exactly the same thing, ie. creating a CNAME file at the root of the gh-pages branch.

like image 29
Alex Avatar answered Jul 29 '26 08:07

Alex



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!