Github:将gh-pages镜像为主

我正在开发一个在GitHub上托pipe的jQuery插件。 它有一个演示包括我手动复制和推动分支gh-pages ,我想要做的是这样,当我推变化master它会自动推到gh-pages ,或在至less有一个设置,他们镜像。

我已经看到这个问题,但不知道它是否真的回答了我的问题,关于这些要求:

  1. 我使用塔 ,我不介意使用terminal(Mac)进行configuration更改,只要解决scheme与这个GUI工作。
  2. 我只想要在某些回购站点上进行“镜像”,而不是在我的机器上进行。

干杯

 git checkout gh-pages git merge master git push origin gh-pages 

将以下两行添加到.git/config[remote "origin"]部分:

 push = +refs/heads/master:refs/heads/gh-pages push = +refs/heads/master:refs/heads/master 

每次你push它会自动将主人推到gh页面。 我正在使用这个jQuery Lifestream项目 。

不要做什么denbuzzebuild议以上 ! 推动中的+(加号)使其静静地接受非快速更新。 我发现困难的方式,这可以通过导致悬而未决的工作不可避免地导致工作失去。 只需删除加号,这是一个更安全的方法。

 push = refs/heads/master:refs/heads/gh-pages push = refs/heads/master:refs/heads/master 

现在,而不是造成强制更新这将导致警告和拉build议

 To https://github.com/someuser/repo.git ! [rejected] master -> gh-pages (fetch first) ! [rejected] master -> master (fetch first) error: failed to push some refs to 'https://github.com/someuser/repo.git' hint: Updates were rejected because the remote contains work that you do hint: not have locally. This is usually caused by another repository pushing hint: to the same ref. You may want to first integrate the remote changes hint: (eg, 'git pull ...') before pushing again. hint: See the 'Note about fast-forwards' in 'git push --help' for details. 

我在@denbuzze和@MCSDWVL答案中增加了进一步的解释。

如果你想在每次运行git push origin时候自动把mastergh-pagesgit push origin ,你可能需要在你的repo的gitconfiguration文件中添加一个Refspec参数。

所以,根据git-scm的书 ,你可以添加两个RefSpecs ,通过添加两个push值到repoconfiguration文件.git/config

 [remote "origin"] url = https://github.com/<github_user>/<repo_name> fetch = +refs/heads/*:refs/remotes/origin/* push = refs/heads/master:refs/heads/master push = refs/heads/master:refs/heads/gh-pages 

这将导致一个git push origin

  1. 将本地master分支推送到远程master分支
  2. 将本地master分支推送到远程gh-pages分支

默认。

注意 :在规范之前使用+会导致强制推送到回购。 谨慎使用它:

refspec的格式是一个可选的+ ,后跟<src>:<dst> ,其中<src>是远程端引用的模式, <dst>是那些引用将在本地写入的地方。 +告诉Git更新参考,即使它不是快进。

我个人喜欢把它换成别名:

 alias gpogh="git checkout gh-pages && git merge master && git push origin gh-pages && git checkout -" 

这将你的主人镜像到gh-pages ,推到github,然后切换回你以前工作的那个分支。

承诺推动主..

然后 :

 git checkout gh-pages // -> go to gh-pages branch git rebase master // bring gh-pages up to date with master git push origin gh-pages // commit the changes git checkout master // return to the master branch 

更新 : GitHub现在允许页面从你想要的任何分支和目录发布。


gh-pages使用gh-pages分支要容易得多。 “主”没有什么不可思议的; 这只是另一个分支名称。 gh-pages有一些神奇的东西,因为这是GitHub寻找index.html来为你的页面服务的地方。

阅读更多关于这个话题的其他答案 。

使用gh-pages作为主也比子树容易,这比子镜像容易。 你可以使用这里或这里描述的git subtree :如果你有一个包含你的演示的目录,你可以用一个命令将这个目录推送到gh-branch 。 假设您将目录的gh-pages命名为清楚。 然后,在您提交并将更改推送给master ,运行以更新gh-pages:

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

问题是如果你的文件在gh-pages引用其他目录下的文件。 符号链接不起作用,所以您必须复制作为gh页面的目录中的文件。

如果您使用gh-pages作为主 ,这个问题将不会发生。

或者你可以使用下面的cmd,这会把你的本地主分支推到gh-pages master分支。 git push -f origin master:gh-pages