13

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

git
  • 131
  • 1
  • 3

3 Answers3

20

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.

christianvuerings
  • 22,500
  • 4
  • 23
  • 19
Jakub Narębski
  • 309,089
  • 65
  • 217
  • 230
  • You meant 'gh-pages' I presume not 'hg_pages' – coderintherye Sep 24 '10 at 03:57
  • I find this works perfectly for the `git push` command, but I haven't been able to get it to work with any of the GitHub for Mac actions (Commit, Commit & Sync, Sync, or even `Push` from the Repository menu). Is there a comparable `git config` line for the `git pull --rebase` command that the GitHub app does (according to http://mac.github.com/help.html). – James Chevalier Jan 30 '12 at 17:55
  • @JamesChevalier: It should work for any push, be it from command line or from GUI. It doesn't affect *pull* at all, though. – Jakub Narębski Feb 05 '12 at 21:47
  • But this way only the branch `origin/gh-pages` will be pushed while `origin/master` remains the same, I have to add `[...] +refs/heads/master:refs/heads/master` too to the configuration. Am I wrong? – cYrus Apr 25 '12 at 14:27
  • @cYrus: This way master will be pushed into gh-pages – Jakub Narębski Apr 26 '12 at 18:23
2

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
Ash Wilson
  • 22,820
  • 3
  • 34
  • 45
  • so if i update master, gh-pages will reflect the updates? and if i add some files to gh-pages, will it still get updates from master? – git Nov 10 '09 at 02:37
  • 1
    Not automatically, no; you'll have to use `git merge` to move changes and files from branch to branch. See http://www.kernel.org/pub/software/scm/git/docs/gittutorial.html#_managing_branches for a good explanation of how branches are used. – Ash Wilson Nov 10 '09 at 02:41
0

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 git@github.com:<username>/<project>.git
cd <project>
git checkout -b gh-pages
git push origin gh-pages
inexistence
  • 29
  • 2
  • 4
divegeek
  • 4,795
  • 2
  • 23
  • 28