Unable to change source branch in GitHub Pages

拟墨画扇 提交于 2020-07-16 16:45:49

问题


I have created a simple web site for GitHub Pages. The source of the site is in the "master" branch and the generated web site (what I want to see published) is under the "gh-pages" branch.

I was expecting to be able to change the source of the site in the settings. However, the setting is grayed out? I cannot change it (see screenshot below). What am I doing wrong? How do I switch to the "gh-pages" branch?


回答1:


Personal or organization sites are built from master. gh-pages branch is used to build sites for projects.

As far as I can see, you're using https://user-name.github.io/ url, this is a personal one, so that's why master branch is the default one.

See the documentation page

If your site is a User or Organization Page that has a repository named <username>.github.io or <orgname>.github.io, you cannot publish your site's source files from different locations. User and Organization Pages that have this type of repository name are only published from the master branch.

So the answer is No, you can not change it. You'll have to adjust your workflow and keep development in another branch (let's call it development) and merge to master when you're ready to publish.




回答2:


FWIW, this is the setup I used for publishing a personal page (i.e. https://user-name.github.io) using Next.js and gh-pages:

  1. Create a different default branch in your repo to work in (e.g. develop)
  2. Build a static export of your site: next build && next export
  3. Put a .nojekyll marker file in the export directory: touch out/.nojekyll
  4. Upload the static export to the master branch: gh-pages -t -b master -d out

You can bundle these commands in package.json to get a convenient yarn deploy command:

scripts: {
  ...
  "build": "next build",
  "export": "yarn run build && next export",
  "deploy": "yarn export && touch out/.nojekyll && gh-pages -t -b master -d out"
  ...



回答3:


Ok so if you are using angular-cli-ghpages it will by default create a new branch gh-pages and publish to it.

Now as a starter, like me, if you are using https://user-name.github.io/ and you want your app to be published from the master branch of your user-name.github.io you can follow the below steps.

  1. Make a production ready build using

    ng build --prod --base-href "/user-name.github.io/"
    
  2. Deploy to the master using angular-cli-ghpages using

    angular-cli-ghpages --branch=master
    

Hope this helps.



来源:https://stackoverflow.com/questions/39978856/unable-to-change-source-branch-in-github-pages

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!