无法更改 GitHub 页中的源分支

Unable to change source branch in GitHub Pages

我为 GitHub 页面创建了一个简单的网站。该站点的来源在 "master" 分支中,生成的网站(我希望看到的已发布)在 "gh-pages" 分支下。

我希望能够在设置中更改网站的来源。但是,设置是灰色的?我无法更改它(请参见下面的屏幕截图)。我究竟做错了什么?如何切换到 "gh-pages" 分支?

个人或组织网站是从 master 构建的。 gh-pages分支用于为项目建站。

据我所知,您使用的是 https://user-name.github.io/ url,这是个人的,所以 master 分支是默认分支。

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.

所以答案是否定的,你不能改变它。您必须调整您的工作流程并在另一个分支中继续开发(我们称之为 development)并在您准备好发布时合并到 master

更新: 现在是 2020 年,所以从 July 31st GitHub 页面允许您配置任何分支作为旧 master

好的,如果您使用 angular-cli-ghpages,它会默认创建一个新分支 gh-pages 并发布到它。

现在作为初学者,像我一样,如果您正在使用 https://user-name.github.io/ 并且您希望从 [=29= 的 master 分支发布您的应用程序]user-name.github.io您可以按照以下步骤操作。

  1. 使用

    进行生产就绪构建
    ng build --prod --base-href "/user-name.github.io/"
    
  2. 部署到 master 使用 angular-cli-ghpages 使用

    angular-cli-ghpages --branch=master
    

希望对您有所帮助。

FWIW,这是我使用 Next.js and gh-pages:

发布个人页面(即 https://user-name.github.io)的设置
  1. 在您的存储库中创建一个不同的默认分支(例如 develop
  2. 构建网站的静态导出:next build && next export
  3. 在导出目录中放一个.nojekyll标记文件:touch out/.nojekyll
  4. 上传静态导出到master分支:gh-pages -t -b master -d out

您可以将这些命令捆绑在 package.json 中以获得方便的 yarn deploy 命令:

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