Github:将 gh-pages 镜像到 master

发布于 2024-11-04 03:55:55 字数 561 浏览 4 评论 0原文

我正在开发一个托管在 GitHub 上的 jQuery 插件。它有一个演示,我手动将其复制并推送到分支 gh-pages,我想做的就是拥有它,这样当我将更改推送到 master< /code> 它会自动推送到 gh-pages,或者至少是它们镜像的设置。

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

  1. 我使用 Tower,我不介意使用终端(Mac)来更改配置,只要解决方案适用于此 GUI。
  2. 我只想在某些存储库上进行这种“镜像”,而不是在我的机器上的所有存储库上进行这种“镜像”。

干杯

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

习惯成性 2024-11-11 03:55:55

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

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

每次 push 时,它都会自动推送 master也到 gh-pages。
我将其用于 jQuery Lifestream 项目

Add the following 2 lines to the [remote "origin"] section of .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.

心欲静而疯不止 2024-11-11 03:55:55
git checkout gh-pages
git merge master
git push origin gh-pages
git checkout gh-pages
git merge master
git push origin gh-pages
静谧 2024-11-11 03:55:55

不要做 denbuzze 上面建议的事情!推送中的 +(加号)使其安静地接受非快进更新。我艰难地发现,这可能会导致悬空提交,从而导致工作的丢失,并且无法挽回。只需删除加号即可使这种方法更安全。

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.

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.

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.
倾城泪 2024-11-11 03:55:55

我正在向 @denbuzze@MCSDWVL 回答。

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

所以,根据 git-scm 书,你可以添加两个 RefSpecs,通过向存储库配置文件.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分支

默认

注意:在规范之前使用 + 会导致强制推送到存储库。谨慎使用:

引用规范的格式是可选的 +,后跟 :,其中 > 是远程端引用的模式, 是在本地写入这些引用的位置。 + 告诉 Git 更新引用,即使它不是快进。

I'm adding further explanation to @denbuzze and @MCSDWVL answers.

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.

So, according to the git-scm book, you can add two RefSpecs, by adding two push values to the repo config file .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:

  1. Push the local master branch to the remote master branch
  2. Push the local master branch to the remote gh-pages branch

by default.

Note: using a + before the spec causes to force push to the repo. Use it with caution:

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.

天赋异禀 2024-11-11 03:55:55

我个人喜欢将其包装在别名中:

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

这会将您的 master 镜像到 gh-pages,推送到 github,然后切换回您正在处理的上一个分支。

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.

ペ泪落弦音 2024-11-11 03:55:55

提交推送到master..

然后:

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

commit and push to 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
無心 2024-11-11 03:55:55

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

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

树深时见影 2024-11-11 03:55:55

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


对我来说,使用 gh-pages 分支作为主分支要容易得多。 “主人”并没有什么神奇的地方。这只是另一个分支名称。 gh-pages 有一些神奇之处,因为 GitHub 就是在其中寻找 index.html 来为您的页面提供服务。

请阅读我关于此主题的其他答案了解更多信息。

使用 gh-pages 作为主树也比子树更容易,而子树又比镜像更容易。您可以按照此处git subtree “http://stevenclontz.com/blog/2014/05/08/git-subtree-push-for-deployment/” rel="nofollow noreferrer">此处:如果您有一个包含演示的目录,您可以使用一个命令将该目录推送到 gh-branch。假设您将目录命名为 gh-pages 以使事情变得清晰。然后,在您提交更改并将其推送到 master 后,运行此命令来更新 gh-pages:

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

问题是,如果 gh-pages 中的文件引用了其他文件中的文件它之外的目录。符号链接不起作用,因此您必须将文件复制到用作 gh-pages 的目录中。

如果您使用gh-pages作为master,这个问题就解决了不会发生。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文