Jim
Jim

Reputation: 4172

Why Is My Github Pages Custom Domain Constantly Reset?

I go into the page in Github (https://github.com/user/repo/settings/pages) and set a custom domain. It works great!

However, every time I deploy (using the gh-pages npm package) it resets the domain back to

 https://user.github.io/repo

This is incredibly frustrating... how can I tell it to use my custom domain permanently?

Upvotes: 16

Views: 3388

Answers (6)

Leonardo Pangaio
Leonardo Pangaio

Reputation: 13

I had the same problem, but in my case I'm using Material for MKDocs to deploy the website.

To solve this, I noticed that the CNAME file was not created (or copied) on the branch that the Github Pages was configured, just moving the CNAME file to the docs folder (in case of MKDocs), but there is the possibility to change the pipeline to create it on the correct branch.

Upvotes: 0

gurf2
gurf2

Reputation: 1

If you are using "npm run deploy" or any npm deployment scripts Add a CNAME.txt file in public your Directory In the 1st line enter your custom domain name in it. e.g. (acbd.com)

else Create and Add the same in you static Directory

Deploy and check

Upvotes: -1

caseydean
caseydean

Reputation: 11

I was having the same problem for a gatsby site, I needed to install the gatsby-plugin-cname package and add the following to the gatsby-config.js

module.exports = {
  siteMetadata: {
    siteUrl: 'http://custom-domain.com/'
  },
  plugins: [
    'gatsby-plugin-cname'
  ],
}

https://www.gatsbyjs.com/plugins/gatsby-plugin-cname/

Upvotes: 1

btholt
btholt

Reputation: 668

For those of you using the GitHub Action crazy-max/ghaction-github-pages there is a setting called fqdn that you're looking for. Set that with the custom domain and it stop breaking every deploy.

See documentation here.

Upvotes: 2

LeOn - Han Li
LeOn - Han Li

Reputation: 10184

For my React static site I have to add below scripts to the package.json to add the CNAME file with the custom domain to the build/ dir before each deployment.

"scripts": {
   "build": "react-scripts build",
   "add-domain": "echo \"myAwesomeDomain.org\" > build/CNAME",
   "deploy": "npm run add-domain && gh-pages -d build",
   "bd": "npm run build && npm run deploy",
},

Upvotes: 3

mnestorov
mnestorov

Reputation: 4484

It looks like there are reports about this in the repo for gh-pages npm package. See #347, #236, #370, #213.

There is even a still opened merged pull-request that tackles the issue through documentation.

Basically, it says:

Modify the deployment line to your deploy script if you use custom domain. This will prevent deployment to remove the domain from settings in github.

echo 'your_cutom_domain.online' > ./build/CNAME && gh-pages -d build"

Edit: there are other options as well, some people directly change their deployment call and add a custom domain to their deployment scritpt:

var ghpages = require('gh-pages');
var fs = require('fs');

fs.writeFile('dist/CNAME', "your-custom-domain.com", function(err) {});
ghpages.publish('dist', function(err) {});

others just follow the advice for putting CNAME to your publishing folder.

Upvotes: 14

Related Questions