git Github:将 gh-pages 镜像到 master
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5807459/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Github: Mirroring gh-pages to master
提问by Ben Everard
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.
我正在开发一个托管在 GitHub 上的 jQuery 插件。它包含一个演示,其中我手动复制并推送到分支gh-pages
,我想做的是拥有它,以便在我推送更改master
时自动推送到gh-pages
,或者至少是镜像的设置.
I've already seen this questionbut not sure if it really answers my question with regard to these requirements:
我已经看过这个问题,但不确定它是否真的回答了我关于这些要求的问题:
- 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.
- I only want this 'mirroring' on certain repos, not on all of them on my machine.
- 我使用Tower,我不介意使用终端 (Mac) 更改配置,只要该解决方案适用于此 GUI。
- 我只希望在某些存储库上进行这种“镜像”,而不是在我的机器上的所有存储库上进行这种“镜像”。
Cheers
干杯
采纳答案by Steve
git checkout gh-pages
git merge master
git push origin gh-pages
回答by christianvuerings
Add the following 2 lines to the [remote "origin"]
section of .git/config
:
将以下 2 行添加到 的[remote "origin"]
部分.git/config
:
push = +refs/heads/master:refs/heads/gh-pages
push = +refs/heads/master:refs/heads/master
Every time you push
it will automatically push master to gh-pages as well.
I'm using this for the jQuery Lifestream project.
每次你push
它也会自动将 master 推送到 gh-pages。我将它用于jQuery Lifestream 项目。
回答by MCSDWVL
Do not do what denbuzze suggests above!! The + (plus sign) in the push makes it quietly accept non-fastforward updates. I found out the hard way that this can irrevocably cause work to be lost by leading to dangling commits. Simply removing the plus signs makes this a safer approach.
不要做上面denbuzze建议的事情!!推送中的 +(加号)使它安静地接受非快进更新。我发现这很难通过导致悬空提交而不可避免地导致工作丢失。简单地删除加号使这是一种更安全的方法。
push = refs/heads/master:refs/heads/gh-pages
push = refs/heads/master:refs/heads/master
now instead of causing a force update this will cause a warning & pull suggestion
现在而不是导致强制更新,这将导致警告和拉取建议
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.
回答by raviolicode
I'm adding further explanation to @denbuzzeand @MCSDWVLanswers.
我正在为@denbuzze和@MCSDWVL答案添加进一步的解释。
If you want to push both to master
and gh-pages
automatically each time you run git push origin
, you probably want to add a Refspec to the git config of your repo.
如果您想在每次运行时都推送到master
和gh-pages
自动git push origin
,您可能希望将 Refspec 添加到您的存储库的 git 配置中。
So, according to the git-scm book, you can add two RefSpecs, by adding two push
values to the repo config file .git/config
:
因此,根据git-scm book,您可以通过向repo 配置文件添加两个值来添加两个 RefSpecs: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
That will cause a git push origin
to:
这将导致git push origin
:
- Push the local
master
branch to the remotemaster
branch - Push the local
master
branch to the remotegh-pages
branch
- 将本地
master
分支推送到远程master
分支 - 将本地
master
分支推送到远程gh-pages
分支
by default.
默认情况下。
Note: using a +
before the spec causes to force push to the repo. Use it with caution:
注意:+
在规范导致强制推送到 repo 之前使用 a 。谨慎使用:
The format of the refspec is an optional
+
, followed by<src>:<dst>
, where<src>
is the pattern for references on the remote side and<dst>
is where those references will be written locally. The+
tells Git to update the reference even if it isn't a fast-forward.
refspec 的格式是一个可选的
+
, 后跟<src>:<dst>
, where<src>
是远程端引用的模式,以及<dst>
这些引用将在本地写入的位置。该+
告诉Git的更新,即使它不是一个快进的参考。
回答by dhulihan
I personally like to wrap this in an alias:
我个人喜欢用别名来包装它:
alias gpogh="git checkout gh-pages && git merge master && git push origin gh-pages && git checkout -"
This mirrors your master to gh-pages
, pushes to github, then switches back the previous branch you were working on.
这将您的 master 镜像到gh-pages
,推送到 github,然后切换回您正在处理的前一个分支。
回答by azl
commitand pushto master..
提交并推送到主..
then :
然后 :
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
回答by DJ Jaiswal
OR you can just use the cmd below, this will push your local master branch to gh-pages master branch.
git push -f origin master:gh-pages
或者您可以只使用下面的 cmd,这会将您的本地 master 分支推送到 gh-pages master 分支。
git push -f origin master:gh-pages
回答by Dan Dascalescu
UPDATE: GitHub now allows pages to be published from any branch and directory you want.
更新:GitHub 现在允许从您想要的任何分支和目录发布页面。
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 issomething magical about gh-pages, because that's where GitHub is looking for index.html to serve your page.
对我来说,将gh-pages
分支用作主分支要容易得多。“大师”并没有什么神奇之处;这只是另一个分支名称。还有就是关于GH-页面神奇的东西,因为这是GitHub上寻找index.html的服务页面。
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 hereor 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:
用gh-pages
作主树也比子树更容易,子树比镜像更容易。您可以git subtree
按照此处或此处的描述使用:如果您有一个包含演示的目录,则可以gh-branch
使用一个命令将该目录推送到。假设您命名目录gh-pages
以使事情清楚。然后在您提交并将更改推送到 后master
,运行此命令以更新 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 copyfiles in the directory that serves as gh-pages.
问题是您的文件是否gh-pages
引用了它之外的其他目录中的文件。符号链接不起作用,因此您必须将文件复制到用作 gh-pages 的目录中。
If you use gh-pages
as master, this problem won't occur.
如果您使用gh-pages
master,则不会发生此问题。