Gabriel Gabriel - 8 months ago 38
Git Question

Working on a project's Github page

I've just cloned a repo I have hosted on Github but this only checked out the

branch. There's also a
branch that Github creates automatically to host the project's site.

I want to also clone (checkout? pull?) this branch to work on it and I've found a lot of material on this that got me a bit confused.

This answer says that I should do:

git checkout -b gh-pages origin/gh-pages

and this one implies the command could be:

git branch -f gh-pages upstream/gh-pages

What is the difference between these two? Should I stick with the first one?

Add. If I do
git branch -a
I get:

remotes/origin/HEAD -> origin/master

  • The first one creates a branch gh-pages if that branch doesn't exist.
  • The second one forces an existing gh-pages branch to upstream/gh-page.

Personally, I prefer declaring gh-pages branch as a submodule.
That allows you to work on master, while seeing/updating the gh-pages content in a gh-pages subfolder (declared as a submodule).

Update August 2016: Simpler GitHub Pages publishing now allows to keep your page files in a subfolder of the same branch (no more gh-pages needed):

Now you can select a source in your repository settings and GitHub Pages will look for your content there.

So you don't even have to checkout another branch now (uf the upstream repo chose the new content organization)