github site from gh-pages branch - github

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:
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 (e.g. 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.

Related

Is it possible to only have one gh-pages repo?

Last year I have been working on a project, that required gh-pages. Everything was totally fine and hosted on Github Pages. Today I started to work on another project, that will also require gh-pages. However when I started pushing local repo to github, I realized something. Somehow this newly created react app already had a remote origin with a link to that first last-year repo. How is it possible? Will my first repo stop working if I use gh-pages with this new project?
gh-pages pages is (or, rather, should be!) a branch not a repo. Your new new project should be in a new repo. Two repos can, of course, both have branches with the same name.
It sounds like you have set up the repos or the remotes for the repos incorrectly. Can you please edit your question to add the URLs of the two repos and the results of running git remote -v in the local checkouts of the two repos.

GitHub Pages Not Rendering HTML or MD Files on Newly Created Repository

I've been working with GitHub Pages but for the life of me my pages will not render.
I've named the repository with the account username along with the postfix of github.io, yet when I go to the designated URL to view the GitLab Pages I get a 404 error.
It's a new account, a new and correctly named repo with Jekyll and HTML pages in the root of the project. Yet 404 errors abound. Any thoughts?
What branch are you on?
GitHub Pages only currently renders files on the master branch. However, new repos do not create a master branch. They create a branch called main to avoid the racist overtones of the term master.
So you will need to create a new branch called master and add Jekyll and HTML files there. Commit and push to GitHub and your GitHub pages will work.
Basically, make sure your files are in the master branch. Soon GitHub Pages will likely use the main branch by default but not yet.

GitHub Pages publishing from master vs master/docs or gh-pages branch

I've been able to publish GitHub sites under my domain on GitHub Pages from the master branch without issue, however in the docs it says to use a gh-pages branch or master/docs for publishing projects.
I also have a repository for my homepage index.html file/assets, where I link to each of the published GitHub repositories (which are published to my domain name.com/repo-name).
Why have I been able to publish from the master branch? Is there any reason to publish from the gh-pages branch or master/docs instead for publishing project repositories?
GitHub Pages can publish from any of those sources: gh-pages branch, master/docs, or just from the repo itself. It's more of a preference which route you use.
For example, Jekyll is publishing using the master/docs option. The rest of the repo outside of the docs folder is for the actual Jekyll code. One possible reason is that PR's with new features must also include documentation of that new feature. Otherwise, it won't get merged.
The gh-pages option means that code and documentation can be paced or managed differently. They live in the same repo, but the branches can grow at differing speeds.
In terms of technical differences, there's no technical costs/benefits to each option as far as I know. It's just how you want to organize your code and documentation.
Hope that helps!
GitHub requires user and organization sites to build from master, while project sites can build from gh-pages. If I understand correctly, you are publishing to your user site, i.e. yourusername.github.io.

github Repository removal/deletion & github pages

If I remove/delete a public repository on gitHub, will it remove all of its clones as well? Secondly I want to share my gaming portfolio on github pages is there any way of doing that without having my repositorys cloned?
If you delete the repo from the GH site, it won't remove any clones created on local machines. It will delete everything on the site repository. You can configure GitHub Pages to publish your site's source files from any of these branches: master, gh-pages, or a /docs folder on your master branch. I'd check out this article, since it explains the details.

If my repo IS my Jekyll site, does gh-pages still need to be an orphan?

There are many suggestions that when you start a gh-pages branch, to start the branch as an orphan and remove the contents from git.
For example, here: http://robots.thoughtbot.com/its-for-the-orphans and on the official github: https://help.github.com/articles/creating-project-pages-manually/
However, would this apply if my master branch is my gh-pages branch? That is to say, my entire repo was created to be a Jekyll site. My assumption is that gh-pages branch and the master branch should be identical.
In the case where the repo is created solely as a Jekyll site, what is the best way to create and maintian the gh-pages branch for a project site? I've had troubles in the past keeping the master branch and gh-pages branches identical. One solution I've been suggested to delete the master branch and have only the gh-pages branch, is this considered bad or good practice and why?
I've also seen this suggestion of nesting repos: https://gist.github.com/chrisjacob/833223 However, it seems like I really do not need a master and a gh-pages, since my repo is only gh-pages.
However, I may also have a basic misunderstanding of this since I started using Jekyll a few days ago, please let me know if it is not correct that gh-pages would be the same as master branch for a Jekyll only project, and why.
Thanks!
master branch is eventually used for :
hosting a user/organisation site (http://github.com/username/username.github.io)
host your Jelyll code if you use a deploying strategy like with octopress (code in master, generated pages in gh-pages), mainly when you need to run plugins locally.
If you simply hosts a project site (http://github.com/username/projectName) that doesn't needs special plugins, you can safely delete master branch and use gh-pages as you main branch.
You can then make a new branch locally for testing purpose, then merge it in gh-pages before pushing to github.
The master branch is not special in any way other than being automatically created when you create a new repo. It can be safely ignored or even deleted if you don't need it.
You can delete it, that's what I do for the majority of my Jekyll sites as it means I don't push to the wrong branch!
In your repo settings just set gh-pages as the default branch and then you can safely delete Master.