我正在开发一个正在GitHub上托管的jQuery插件。它包含一个演示,我正在手动复制并将其推到分支机构 gh-pages, ,我想做的就是拥有它,所以当我将更改推到 master 它自动推到 gh-pages, ,或至少在镜像的设置中。

我已经看过 问题 但不确定是否真的回答了我关于这些要求的问题:

  1. 我用 , ,只要解决方案与此GUI一起使用,我不介意使用终端(MAC)进行更改。
  2. 我只希望在某些存储库上进行“镜像”,而不是在我的机器上所有的镜像。

干杯

有帮助吗?

解决方案

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

其他提示

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

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

每次你 push 它也将自动将主机推到GH页面。我正在将其用于 jQuery Lifestream项目.

不要做Denubuzze上面建议的!!推送中的 +(加号)使其悄悄地接受非快速更新。我发现艰难的方式是,这可以通过导致悬空的命令而无法撤销地导致工作损失。简单地删除加号的标志使这是一种更安全的方法。

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

现在,而不是引起力量更新,这将引起警告和拉建议

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: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

我正在添加进一步的解释 @denbuzze@mcsdwvl 答案。

如果您想将两者推到 mastergh-pages 每次运行时都会自动 git push origin, ,您可能想在存储库的GIT配置中添加RefSpec。

因此,根据 git-scm书, ,您可以添加两个 refspecs, ,通过添加两个 push 值到repo配置文件 .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,然后切换回您正在工作的先前分支。

或者,您可以只使用下面的CMD,这将把您的本地主分支推向GHPAGES主分支。git push -f origin master:gh-pages

犯罪 掌握..

然后 :

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页面的神奇之处,因为Github正在寻找index.html以提供您的页面。

阅读更多信息 我对这个话题的另一个答案.

使用 gh-pages 因为主人也比子树更容易,这比镜像更容易。您可以使用 git subtree 如上所述 这里 或者 这里: :如果您的目录包含您的演示,则可以将该目录推向 gh-branch 用一个命令。假设您命名目录 gh-pages 使事情变得清晰。然后,您承诺并将更改推到 master, ,运行此以更新GH页面:

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

问题是您的文件是否 gh-pages 请参阅外部其他目录中的文件。符号链接不起作用,所以您必须 复制 目录中用作GH页面的文件。

如果你 利用 gh-pages 作为主人, ,不会发生这个问题。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top