github 来自 gh-pages 分支的网站

github site from gh-pages branch

我有 GitHub 个像 example.github.io 这样的网站,想从 gh-pages 分支加载这个网站! 我该怎么办?

现在我无法更改分支,因为我的存储库名称是 example.github.io

当您创建 yourusername.github.io 时,您必须直接提交给 master。它的意思是一个网站(不像一个 repo,它有一个托管到 yourusername.github.io/reponame/* 的网站。

由于您已经有了网站的分支,只需将其合并到 master 分支即可。这可以从命令行、Github 网站或 Github 桌面完成。


逻辑

示例:您有一个存储库 (username.github.io)。您还设置了两个包含 Github 页的回购协议:repo-1repo-2.

username.github.io 是根。你几乎可以用它做任何你想做的事。创建目录将相对于域的根目录。当您连接到域时,它会从 master 分支中找到文件。如果您进入 username.github.io 的回购设置,您将看到:

您已锁定到 master 分支。您仍然可以使用其他分支来添加功能,但实际网站包含的是 master 分支上的内容。

username.github.io 存储库与 repo-1repo-2 的区别在于 username.github.io 允许编辑访问根目录(例如 http(s)://username.github.io/index.html),其中因为 repo-1 及其连接的页面将位于 http(s)://username.github.io/reponame/index。由于该网站很可能希望远离源本身,因此您可以使用备用分支来托管它。

如果您进入 repo-1repo-2 的设置,您会看到:

在这里你可以选择。如果您有多个分支机构,您可以 select 一个不同的分支机构来托管页面。您还可以 select 为网站使用 /docs 文件夹的选项。


TL:DR; 使用 username.github.io 时,master 分支是实际托管网站的分支。将其视为生产分支。其他无法从网站访问

来自 OP 的

So I can't use the gh-pages branch for Github site! yes?

2020 年 9 月更新:是的,你现在可以了。
你可以使用任何你想要的分支。

"Build and deploy GitHub Pages from any branch"

Repositories that use GitHub Pages can now build and deploy from any branch.
Publishing to the special gh-pages branch will still work the same as it always has, but you can now choose a different branch in your repository as the publishing source.
This functionality also removes the hardcoded dependency on user and organization pages having a master branch.