1

I've just cloned a repo I have hosted on Github but this only checked out the master branch. There's also a gh-pages 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
remotes/origin/gh-pages
remotes/origin/master
Community
  • 1
  • 1
Gabriel
  • 40,504
  • 73
  • 230
  • 404

1 Answers1

1
  • 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)

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • And what does the first one do if the `gh-pages` branch already exists (my case)? Which one should I use if I want to work on my already existing `gh-pages` branch? I'll check out working with a submodule, never seen that before. – Gabriel Sep 08 '14 at 13:28
  • @Gabriel if the branch already exist, the command will fail. The second will not. – VonC Sep 08 '14 at 13:29
  • VonC tried the 2nd command (`git branch -f gh-pages upstream/gh-pages`) and I got: `fatal: Not a valid object name: 'upstream/gh-pages'.` – Gabriel Sep 08 '14 at 13:34
  • 1
    @Gabriel you need to adapt it to the name of your upstream repo: `git remote -v`: most likely 'origin' in your case. `git branch -f gh-pages origin/gh-pages` – VonC Sep 08 '14 at 13:37
  • 1
    @Gabriel the second answer you mention uses 'upstream' in the context of a GitHub fork: read my answer: http://stackoverflow.com/a/9257901/6309 – VonC Sep 08 '14 at 13:38
  • Thanks for all the detailed answers @VonC! – Gabriel Sep 08 '14 at 14:34