Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why Is My Github Pages Custom Domain Constantly Reset? [closed]

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?

like image 695
Jim Avatar asked Dec 04 '25 05:12

Jim


2 Answers

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.

like image 77
mnestorov Avatar answered Dec 07 '25 03:12

mnestorov


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",
},

like image 38
LeOn - Han Li Avatar answered Dec 07 '25 03:12

LeOn - Han Li