Github: Mirroring gh-pages to master

2019-01-20 21:40发布

I'm developing a jQuery plugin that's being hosting on GitHub. It has a demo included of which I'm manually copying and pushing to the branch gh-pages, what I'd like to do is have it so when I push a change to master it is automatically pushed to gh-pages, or at least a setup where they are mirrored.

I've already seen this question but not sure if it really answers my question with regard to these requirements:

  1. I use Tower, I don't mind using the terminal (Mac) to make changes to config, so long as the solution works with this GUI.
  2. I only want this 'mirroring' on certain repos, not on all of them on my machine.

Cheers

8条回答
走好不送
2楼-- · 2019-01-20 22:09
git checkout gh-pages
git merge master
git push origin gh-pages
查看更多
手持菜刀,她持情操
3楼-- · 2019-01-20 22:12

UPDATE: GitHub now allows pages to be published from any branch and directory you want.


It was much easier for me to use the gh-pages branch as master. There's nothing magical about "master"; it's just another branch name. There is something magical about gh-pages, because that's where GitHub is looking for index.html to serve your page.

Read more in my other answer on this topic.

Using gh-pages as master is also easier than subtrees, which are easier than mirroring. You could use git subtree as described here or here: if you have a directory which contains your demo, you can push that directory to the gh-branch with one command. Let's say you name the directory gh-pages to make things clear. Then after you've committed and pushed your changes to master, run this to update gh-pages:

git subtree push --prefix gh-pages origin gh-pages

The problem is if your files in gh-pages refer to files in other directories outside it. Symlinks don't work, so you'll have to copy files in the directory that serves as gh-pages.

If you use gh-pages as master, this problem won't occur.

查看更多
登录 后发表回答