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

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.

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

Can GitHub pages automatically build a Jekyll site on commit to gh-pages?

I am learning how to use jekyll and would love it if someone could explain how to set it up so that whenever I commit the jekyll files to the gh-pages branch, the site would be automatically generated.
Thank you
Reading the documentation pointed by #thirtythreeforty's comment
For User Pages, use the master branch in your username.github.io repository. For Project Pages, use the gh-pages branch in your project's repository.
if your repository is at github.com/userName/userName.github.io it's your user repo -> publish to master
any other repository like github.com/userName/projectName is a project repository -> publish to gh-pages
So, be sure to commit in the right branch.
If the problem is elsewhere you can give your repository url for further investigation.

Is there a way to use a pre/post commit hook in github to update gh-pages branch from master?

I have a completely static site (eg. https://github.com/robertjchristian/angular-enterprise-seed) hosted on github, where I work mostly out of the master branch. The contents of the /app/ directory are byte-for-byte what I want to host. So during development I just cd ~/projects/angular-enterprise-seed/app, and then "python -m SimpleHTTPServer". This allows me to browse the site locally at localhost:8000.
I want to host the static contents of /app on the web as well, and gh-pages is the ideal candidate. Here are my requirements:
Don't want to "just use gh-pages branch as master"
Don't want to rely on a wrapper script that keeps gh-pages in line with master changes from the client.
Don't want to build out a service to handle the webhook post, checkout from master, and check into gh-pages.
Ideally it would be a github hook that says "Post commit hook - sync gh-pages with change in master"
Any ideas?
Thanks.
After reading through a variety of different solutions for handling the sync between master and gh-pages, I ended up adopting an approached favored by JavaScript guru Sindre Sorhus and others:
Make the gh-pages branch the default one on GitHub
Delete the master branch
Use the gh-pages branch as master.
You can see this on GitHub in Sindre's screenful.js repo, or in my project, selection-menu.

How to push only specific folders from Master branch to gh-pages branch?

I'm fairly new to github and web development in general. So say I have all of my project files on my Master branch and I want to push only the files needed to make my page run on gh-pages. How would I tell it to only push certain files to the new gh-pages branch? For example, when you use gulp or grunt it makes a folder that is your rendered site for previewing your site. How would I push only the contents from that site folder to gh-pages without adding all of the other unecessary that are on the Master branch?
I've been using Jekyll recently because you can still push all of the files onto gh-pages and it still works. But I have 2 repositories for a lot of my projects. One repository has all of the source files and then the other repository has only the files I need to push a working site onto gh-pages. I want to clean up my github page so it is more organized.
Thank you.
I know this is an old question, but for the benefit of newcomers to Git branches / gh-pages that might stumble across this problem, I found the least complicated way of moving files or folders from a master branch to a gh-pages branch is to do the following.
# First switch to the gh-pages branch
git checkout gh-pages
# Next checkout the specific file you wish to add to the gh-pages branch
git checkout master -- <path/to/file/folders/on/master/branch>
# Perfom the commit
git commit -m "Updated index.html from master"
# And push
git push
Assuming the file(s) you are trying to add to the gh-pages branch exist on the master branch you shouldn't have any problems following the above steps.
If you are using nodejs and npm you can use the gh-pages package from the command line to publish to a gh-pages branch from a specific directory. The gh-pages package has a command line utility.
Installing the package creates a gh-pages command line utility. Run gh-pages --help to see a list of supported options.
Note: You mentioned using Gulp and there is an npm package called gulp-gh-pages that I use successfully to create gulp tasks to put into my deploy workflow.
I believe you're looking for git subtree merge.
The idea of the subtree merge is that you have two projects, and one of the projects maps to a subdirectory of the other one and vice versa.
When you specify a subtree merge, Git is smart enough to figure out that one is a subtree of the other and merge appropriately — it’s pretty amazing.