git
git

Reputation: 131

github how to include files from master in new git branch gh-pages

github has this feature where you can publish "Project Pages" if you create a new branch gh-pages in your project. For full description see http://pages.github.com/

My project is just html/images, so I just want to serve the master branch.

so how do I create a new branch called gh-pages that is just exact copy of master? some kind of link operation?

Thanks

Upvotes: 13

Views: 3104

Answers (3)

divegeek
divegeek

Reputation: 5032

Create a local clone of your repository, create a new local branch called gh-pages, then push that new local branch to your repository, on the branch gh-pages

git clone [email protected]:<username>/<project>.git
cd <project>
git checkout -b gh-pages
git push origin gh-pages

Upvotes: 0

Jakub Narębski
Jakub Narębski

Reputation: 323752

You want branch 'gh-pages' in your GitHub repository to be the same as 'master' branch. The simplest solution would be to configure git to push branch 'master' to 'gh-pages' automatically.

Assuming that your GitHub repository you push into is configured as 'origin' remote, you can somply do:

$ git config --add remote.origin.push +refs/heads/master:refs/heads/gh-pages

Or if you prefer you can simply edit .git/config file directly.

Then when you do git push or git push origin you would push 'master' branch in your repository into 'gh-pages' branch into repository on GitHub.

See git-push manpage for documentation and description of refspec format.

Upvotes: 20

Ash Wilson
Ash Wilson

Reputation: 24478

That's actually the default behavior of the git branch command. The more complicated symbolic-ref and clean commands you see listed in the "pages" writeup are needed to avoid doing exactly this.

So, at your project root, on the master branch:

git branch gh-pages
git checkout gh-pages

Or just:

git checkout -b gh-pages

Upvotes: 2

Related Questions