简体   繁体   中英

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! how can I do?

now I can't change branch because my repository name is example.github.io

When you create yourusername.github.io you have to commit directly to master. It's meant as a website (unlike a repo that has a website that hosts to 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.


The logic

Example: You have a repo ( username.github.io ). You also have two repos set up with Github pages: repo-1 and repo-2 .

username.github.io is the root. 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:

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

You're locked to the master branch. 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 . 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:

在此处输入图片说明

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.


TL:DR; When using username.github.io , the master branch is the one that actually hosts the website. Think of it as the production branch. The others can't be accessed from the website

From the OP's comment :

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

Update Sept. 2020: yes, you now can.
You can use any branch you want.

" 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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