tags:

views:

386

answers:

3

I've read the guide, which tells you to do the following:

  1. create a .github.com repository
  2. check it out to path/to/repo
  3. cd /path/to/repo
  4. git symbolic-ref HEAD refs/heads/gh-pages
  5. rm .git/index
  6. git clean -fdx
  7. echo "My GitHub Page" > index.html
  8. git add .
  9. git commit -a -m "First pages commit"
  10. git push origin gh-pages

I've done that. And the page shows up. Then I moved to a different computer and checked out the repository again. Now I have a "master" branch in my local, but no "gh-pages." And following steps 3-6 above leaves me with no files in that branch. How do I get the files from "master" into the branch that will publish to GitHub?

I tried git checkout master && git push origin gh-pages but that yields

error: src refspec gh-pages does not match any.
fatal: The remote end hung up unexpectedly
error: failed to push to '[email protected]:<me>/<me>.github.com.git'
+1  A: 

To work on a branch of a fresh remote repository checkout you will first need to create the branch locally. Here is an example for a “gh-pages” branch:

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

More details in this article "Migrating project websites to github pages"

VonC
I don't think that the gh-pages branch exists remotely or locally. I get "git checkout: updating paths is incompatible with switching branches/forcing. Did you intend to checkout 'origin/gh-pages' which can not be resolved as commit?"
James A. Rosen
Strange, in a new gitHub repos, gh-pages does exist from its creation. Since a git clone does bring only remote branches, the checkout --track is needed to make a local branch.
VonC
+1  A: 

Apparently subsequent pushes to "origin master" actually do the trick! It's not documented in the guide, though.

James A. Rosen
The reason is that the @gh-pages branch is only required for existing projects. If your project is called <me>.github.com (that is, you can find it at http://github.com/<me>/<me>.github.com/tree/master), then the master branch works!
James A. Rosen
Found this question via Google. This helped me, thanks. I used the "generate project page" link and it created the index.html in my repository, but it was not published until I did a subsequent push with a minor edit of the page.
Dan Dyer
+2  A: 

As Gaius says, you are following the directions for 'Project Pages', but you are not trying to create a project page, you are trying to create a user page. Creating a user page is much easier - you just create a '.github.com' repository then push your website files to it's master branch, like you would any other normal project.

The instructions you are trying to follow are for adding a parallel branch containing website files to an already existing project. We don't want to make you add a 'website' subdirectory or something to your project, so instead we have you create a completely new branch and push your website to that unrelated branch - thus the Git trickery there.

Scott Chacon