Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deploying seems to overwrite custom domain #213

Open
unlikenesses opened this issue Nov 13, 2017 · 25 comments
Open

Deploying seems to overwrite custom domain #213

unlikenesses opened this issue Nov 13, 2017 · 25 comments

Comments

@unlikenesses
Copy link

I am deploying a GatsbyJS site to GitHub pages with this command:

gatsby build --prefix-paths && gh-pages -d public -b master

I need to push to the master branch because it's a user site (rather than a project site). This works but each time I do it, the repo's "Custom domain" setting is reset. This means after every deploy I need to go into the settings and re-enter the custom domain. No idea if this is a bug or if I'm just missing something obvious.

@atav32
Copy link

atav32 commented Nov 15, 2017

also getting this bug...

@youfoundron
Copy link

youfoundron commented Nov 24, 2017

@unlikenesses @atav32

It seems you need to include a file named CNAME at the root of your file structure.
Your custom domain should be the first line in this file.

In my case, the CNAME file would have this content:

youfoundron.com

Credit goes to this comment.

@pablorsk
Copy link

Just adapt this lines to your DEPLOYMENT script

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

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

@dijs
Copy link

dijs commented Feb 13, 2019

I came across the same issue and just added a npm script for this before publishing.

"add-domain": "echo \"customdomain.com\" > build/CNAME",

@vittorio
Copy link

If you use gh-pages for React app deployment – just put CNAME file with your domain into public folder.

kosich added a commit to onepagehistory/onepagehistory that referenced this issue Apr 10, 2019
Github pages custom url was reset after each deployment
For details see tschaub/gh-pages#213
xnt pushed a commit to xnt/xnt.github.io that referenced this issue Jun 2, 2019
b5 added a commit to qri-io/website that referenced this issue Jul 10, 2019
build script needs to write a file called CNAME to the publish directory. More info: tschaub/gh-pages#213 (comment)
kosich added a commit to onepagehistory/onepagehistory that referenced this issue Oct 31, 2019
Github pages custom url was reset after each deployment
For details see tschaub/gh-pages#213
@giteshjha
Copy link

For angular 8.
Create a CNAME file inside the src folder.
then Inside angular.json
"assets": [
"src/favicon.ico",
"src/assets",
"src/CNAME" // This is the change you need to make.
],

@dhedegaard
Copy link

It would be nice if this behavior was documented in the README.

@harivamshi81189
Copy link

If you use gh-pages for React app deployment – just put CNAME file with your domain into public folder.

Thank you it helped

@MohammedAl-Mahdawi
Copy link

If you are using Gatsby just create a CNAME file inside the static folder and put your domain inside it like example.com

@makenziebird
Copy link

For Hugo, I moved the CNAME file to the "public" directory as that is where the static site resources and assets are built by the GitHub Action.

@iamlasse
Copy link

@iamlasse

Is the CNAME file present at root after building for your github pages branch?

If not, which tool are you using to bundle your static assets?

Yes, the CNAME file is in the root in gh-pages branch with the domain as the only text inside.

@flaviusburca
Copy link

same problem here: CNAME file is in the build/ folder, but the custom domain keeps resetting...

@dimitarangelkov
Copy link

same problem here. CNAME available in the gh-pages branch root folder and the GitHub Pages custom domain keeps resetting on every deploy

@rivka99
Copy link

rivka99 commented Aug 5, 2022

I was also having this same issue as @dimitarangelko. It turned out the issue was that there were slightly different formats of the link in the CNAME files and In the package.json "add-domain": script line

it was "add-domain": "echo "https://mypage.app\" > build/CNAME",
and it had https://mypage.app/ in the gh-pages branch CNAME file, but had just mypage.app in the master branch CNAME file. I switched them all to just mypage.app like so

public/CNAME (in master): mypage.app
CNAME file (in GH-Pages): mypage.app
and in package.json: "add-domain": "echo "mypage.app" > build/CNAME",

made sure that the correct domain was set up in github pages before doing this and pulled them in in the gh-pages branch. Saved it all and ran npm run deploy and it finally didn't replace it!

@SaadBazaz
Copy link

CNAME file is in my main and gh-pages branches, and at the root of each. But this still happens. Any ideas?

I'm building a Vite React app, I use GitHub actions to build and push to gh-pages branch.

Junoth added a commit to Junoth/junoth.github.io that referenced this issue Nov 26, 2022
Junoth added a commit to Junoth/junoth.github.io that referenced this issue Nov 26, 2022
Rthe1st added a commit to Rthe1st/sleeping-sully that referenced this issue Dec 26, 2022
Rthe1st added a commit to Rthe1st/sleeping-sully that referenced this issue Dec 26, 2022
@angles-n-daemons
Copy link

For Hugo (as mentioned above) you can add the CNAME like so from the root of your directory:

$ mkdir -p public
$ echo 'www.<yourdomain>.com' > public/CNAME

Adding this because I wasn't sure exactly where the public directory should be, and I didn't know what a CNAME file contained.

@fguisso
Copy link

fguisso commented Oct 16, 2023

I have the same problem using Hugo.

  • I'm using the deploy from branch gh-pages
  • the CNAME is set in both branches main and gh-pages

I think this worked fine before the option deploy using github actions, and I never chose this option because I have my own actions to build and update the branch gh-pages. I think that the problem is something in the new way that github handles the deployment.

@ani-per
Copy link

ani-per commented Oct 19, 2023

I have the same problem using Hugo.

  • I'm using the deploy from branch gh-pages
  • the CNAME is set in both branches main and gh-pages

I think this worked fine before the option deploy using github actions, and I never chose this option because I have my own actions to build and update the branch gh-pages. I think that the problem is something in the new way that github handles the deployment.

I am using Sphinx, but I fixed this by adding CNAME to the directory from which Pages deploys the source.

E.g., if your build.yml is directing Pages to use the build/ subfolder of root for deployment, then add CNAME to build/ in the main branch.

@fguisso
Copy link

fguisso commented Oct 21, 2023

I have the same problem using Hugo.

  • I'm using the deploy from branch gh-pages
  • the CNAME is set in both branches main and gh-pages

I think this worked fine before the option deploy using github actions, and I never chose this option because I have my own actions to build and update the branch gh-pages. I think that the problem is something in the new way that github handles the deployment.

I am using Sphinx, but I fixed this by adding CNAME to the directory from which Pages deploys the source.

E.g., if your build.yml is directing Pages to use the build/ subfolder of root for deployment, then add CNAME to build/ in the main branch.

I do that.
https://github.com/fguisso/fguisso.github.io/blob/gh-pages/CNAME

image

I follow the file to show to you and noticing that every deploy removes de CNAME file, but this actions is not setting by me: https://github.com/fguisso/fguisso.github.io/commits/gh-pages/CNAME

serena-marie added a commit to serena-marie/portfolio that referenced this issue Nov 1, 2023
Per tschaub/gh-pages#213 (comment), otherwise deploying  will overwrite CNAME record
soufrabi added a commit to soufrabi/blog that referenced this issue Nov 26, 2023
rafal-truszkowski-vga added a commit to Very-Good-Apps-LLC/verygoodapps.co that referenced this issue Apr 21, 2024
jesseez added a commit to doyourownswing/doyourownswing.github.io that referenced this issue May 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests