简体   繁体   English

来自 gh-pages 分支的 github 站点

[英]github site from gh-pages branch

I have GitHub site like example.github.io and want to load this site from the gh-pages branch!我有像example.github.io这样的 GitHub 站点,想从 gh-pages 分支加载这个站点! how can I do?我该怎么办?

now I can't change branch because my repository name is example.github.io现在我无法更改分支,因为我的存储库名称是example.github.io

When you create yourusername.github.io you have to commit directly to master.当你创建yourusername.github.io你必须直接提交给 master。 It's meant as a website (unlike a repo that has a website that hosts to yourusername.github.io/reponame/* .它意味着作为一个网站(不像一个拥有托管到yourusername.github.io/reponame/*的网站的存储库。

Since you already have a branch with the website, just merge it into the master branch.由于您已经在网站上有一个分支,只需将其合并到主分支即可。 This can be done from the command line, the Github website or Github Desktop.这可以从命令行、Github 网站或 Github 桌面完成。


The logic逻辑

Example: You have a repo ( username.github.io ).示例:您有一个仓库( username.github.io )。 You also have two repos set up with Github pages: repo-1 and repo-2 .您还使用 Github 页面设置了两个存储库: repo-1repo-2

username.github.io is the root. username.github.io是根。 You're free to do pretty much anything you want with it.你可以自由地用它做任何你想做的事情。 Creating directories will be relative to the root of the domain.创建目录将相对于域的根目录。 When you connect to the domain, it finds the files from the master branch.当您连接到域时,它会从主分支中找到文件。 If you go into the repo settings for username.github.io , you'll see this:如果你进入username.github.io的 repo 设置,你会看到:

用户页面必须从 master 分支构建

You're locked to the master branch.你被锁定在 master 分支。 You can still use other branches for adding features, but what the actual website consists of is what's on the master branch.您仍然可以使用其他分支来添加功能,但实际网站由主分支上的内容组成。

The difference between the username.github.io repo and repo-1 or repo-2 is that username.github.io allows editing access to the directory root (eg http(s)://username.github.io/index.html ) where as repo-1 and its connected pages would be at http(s)://username.github.io/reponame/index . username.github.io repo 和repo-1repo-2之间的区别在于username.github.io允许编辑访问目录根目录(例如http(s)://username.github.io/index.html ) 其中repo-1及其连接的页面将位于http(s)://username.github.io/reponame/index Since the website is most likely wanted to stay out of the source itself, you can use an alternate branch to host it.由于该网站很可能希望远离源本身,因此您可以使用备用分支来托管它。

If you go into settings for repo-1 or repo-2 , you'll see this:如果您进入repo-1repo-2 ,您会看到:

在此处输入图片说明

Here you can pick.在这里你可以挑选。 If you have multiple branches, you can select a different one to host the pages.如果您有多个分支,您可以选择一个不同的分支来托管页面。 You can also select the option to use the /docs folder for the website.您还可以选择使用网站的/docs文件夹的选项。


TL:DR; TL:博士; When using username.github.io , the master branch is the one that actually hosts the website.使用username.github.io ,主分支是实际托管网站的分支。 Think of it as the production branch.将其视为生产分支。 The others can't be accessed from the website其他网站无法访问

From the OP's comment :来自 OP 的评论

So I can't use the gh-pages branch for Github site!所以我不能在 Github 站点上使用gh-pages分支! yes?是吗?

Update Sept. 2020: yes, you now can. 2020 年 9 月更新:是的,您现在可以了。
You can use any branch you want.你可以使用任何你想要的分支。

" Build and deploy GitHub Pages from any branch " 从任何分支构建和部署 GitHub 页面

Repositories that use GitHub Pages can now build and deploy from any branch.使用 GitHub Pages 的存储库现在可以从任何分支构建和部署。
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.发布到特殊的gh-pages分支仍然会像往常一样工作,但您现在可以在存储库中选择不同的分支作为发布源。
This functionality also removes the hardcoded dependency on user and organization pages having a master branch.此功能还消除了对具有master分支的用户和组织页面的硬编码依赖性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM