Github:镜像gh页面掌握

Ben*_*ard 67 git github github-pages git-tower

我正在开发一个在GitHub上托管的jQuery插件.它包含了一个演示,其中我手动复制并推送到分支机构gh-pages,我想要做的是这样,当我推动更改master它时会自动推送到gh-pages,或者至少是一个设置它们被镜像.

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

  1. 我使用Tower,我不介意使用终端(Mac)对配置进行更改,只要该解决方案适用于此GUI.
  2. 我只希望在某些回购中"镜像",而不是在我的机器上的所有回购.

干杯

chr*_*ngs 106

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

push = +refs/heads/master:refs/heads/gh-pages
push = +refs/heads/master:refs/heads/master
Run Code Online (Sandbox Code Playgroud)

每次你push都会自动将master推送到gh-pages.我正在将它用于jQuery Lifestream项目.

  • 这很酷,除了这个更改没有被检入项目,因此每个人都可以在他们的本地框上手动进行更改.它很容易迷路. (4认同)

Ste*_*eve 66

git checkout gh-pages
git merge master
git push origin gh-pages
Run Code Online (Sandbox Code Playgroud)


小智 27

不要做什么denbuzze建议上面 !! 推送中的+(加号)使其能够安静地接受非快速更新.我发现这很难以通过导致悬空提交而不可逆转地导致工作丢失.简单地删除加号使这更安全.

push = refs/heads/master:refs/heads/gh-pages
push = refs/heads/master:refs/heads/master
Run Code Online (Sandbox Code Playgroud)

现在而不是导致强制更新,这将导致警告和拉动建议

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.
Run Code Online (Sandbox Code Playgroud)

  • @MCSDWVL:你为什么不对denbuzze的答案发表评论? (3认同)

rav*_*ode 9

我正在为@denbuzze@MCSDWVL答案添加进一步的解释.

如果你想在每次运行时自动推送mastergh-pages自动git push origin,你可能想要在你的仓库的git配置中添加一个Refspec.

因此,根据git-scm书,您可以通过向repo配置文件添加两个值来添加两个 RefSpec:push.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
Run Code Online (Sandbox Code Playgroud)

这将导致git push origin:

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

默认情况下.

注意:+在规范之前使用a 会导致强制推送到repo.请谨慎使用:

refspec的格式是可选的+,其后是<src>:<dst>,<src>远程端的引用模式,以及<dst>这些引用将在本地写入的位置.+告诉Git的更新基准,即使它不是一个快进.