git 分支:gh-pages
我在 GitHub 上有一个存储库。最近我发现了 GitHub 的页面,我想使用它们。
我想创建这个新分支,然后在需要时在 master
分支或 gh-pages
分支上提交。
我该怎么做?我是否必须在我的存储库中创建另一个文件夹?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(9)
最新版本的 git 有一个替代 Chandru 解释的 git symbolic-ref 方法的方法。这避免了必须使用较低级别的命令。
More recent versions of git have an alternative to the
git symbolic-ref
method that Chandru explained. This avoids having to use the lower level commands.您可能会发现本教程很有用:
将 GitHub Pages“gh-pages”分支和“master”分支设置为父项目的子文件夹文件夹(“grandmaster”)。
对我来说,这种方法似乎比每次想要编辑 gh-pages 内容时执行 git checkout gh-pages 更简单。让我知道您的想法^_^
编辑:我更新了教程链接 - 感谢@Cawas。旧教程(不推荐)是 https://gist.github.com/825950
You might find this tutorial useful:
Setup GitHub Pages "gh-pages" branch and "master" branch as subfolders of a parent project folder ("grandmaster").
To me this approach seems simpler then doing a
git checkout gh-pages
each time you want to edit your gh-pages content. Let me know what you think ^_^Edit: I updated the tutorial link - thanks @Cawas. The old tutorial (not recommended) was https://gist.github.com/825950
在本地克隆上,
然后,
git checkout gh-pages
并编写页面。当您准备好发布页面时,git push origin gh-pages
。On your local clone do,
Then,
git checkout gh-pages
and write your pages.git push origin gh-pages
when you're ready to publish the pages.您的问题还有另一种解决方案:忘记 gh-pages 和分支;将应该提供的静态文件放入
/docs
目录中,然后转到项目设置并告诉 github 提供/docs
内容。有关更多信息,请查看 这个
There's yet another solution to your problem: Forget about
gh-pages
and branching; Put your static files that are supposed to be served inside/docs
directory and then go to your project settings and tell github to serve/docs
content.For more information take a look at this
发布一个静态站点,如下所示:
其中
www
是静态文件所在的文档根目录。您的静态站点现已上线:
https://[user_name].github.io/[repo_name]/
Publish a static site like this:
Where
www
is the doc root directory in which your static files are.Your static site is now live at:
https://[user_name].github.io/[repo_name]/
https://help.github.com/articles/creating-project-pages-手动
https://help.github.com/articles/creating-project-pages-manually
您的 gh-pages 和 master 分支是否具有完全相同的文件夹结构?如果是这样的话,为什么你还想有两个分支机构呢?只需维护一个 gh-pages 分支即可!但是,如果出于某种原因您希望两个分支不断同步,那么最好的选择是使用 git rebase。请参阅此处:
http://lea.verou。 me/2011/10/easily-keep-gh-pages-in-sync-with-master/
您还可以仅从 master 中挑选您需要的文件,并使用特殊用例将它们推送到 gh-pages 上
git checkout
。请参阅此处:http://oli.jp/2011/github-pages-workflow/ #gh-pages-workflow
http://nicolasgallagher.com/git-checkout-specific-files- from-another-branch/
在不得不解决同样的问题后,我发现 gh-pages 通常最终会拥有与 master 不同的代码库。换句话说,gh-pages 应该只包含项目的 dist/build/publish 文件夹的内容,而 master 将包含你的配置文件、未缩小的脚本和样式等。
我的建议是将 gh-pages 创建为
--orphan
分支,并且仅包含可立即发布的材料。您必须从不同的本地目录中的 master 克隆,使用 git checkout --orphan gh-pages 来创建 gh-pages,然后使用 git rm -rf 删除所有不必要的文件.。添加仅发布文件后,您可以从那里继续推送到 gh-pages。请参阅 Github 文档以获取更多信息:
https://help.github.com/articles/creating-project-pages-手动/
祝你好运
Are your gh-pages and master branch having EXACTLY the same folder structure? If this is the case why do you even want to have two branches? just maintain one gh-pages branch! but if for whatever reason you want to have both branches that are constantly synced then your best bet is to use
git rebase
. See here:http://lea.verou.me/2011/10/easily-keep-gh-pages-in-sync-with-master/
You can also cherry pick only the files you need from master and push them onto gh-pages using a special use case of
git checkout
. See here:http://oli.jp/2011/github-pages-workflow/#gh-pages-workflow
http://nicolasgallagher.com/git-checkout-specific-files-from-another-branch/
Having had to tackle with the same problem I've come to find that gh-pages will usually end up having a different code base than master. In other words, gh-pages should only include the content of the dist/build/publish folder of your project whereas master will include your config files, unminified scripts and styles etc.
My suggestion would be to create gh-pages as an
--orphan
branch and only include the publication-ready material in it. You would have to clone from your master in a different local directory, usegit checkout --orphan gh-pages
to create gh-pages and then delete all the unnecessary files usinggit rm -rf .
. From there you can go on and push to gh-pages after having added your publish-only files.Refer to Github docs for more info:
https://help.github.com/articles/creating-project-pages-manually/
Good luck
典型的方法是切换分支:如果您想在 master 上工作,则使用 git checkout master ;如果您想在 gh-pages 上工作,则切换分支 git checkout gh-pages 。 。
从 git 2.5 开始,您可以同时签出两个分支(在不同的目录中)。请参阅 https://github.com/博客/2042-git-2-5-包括多个工作树和三角形工作流程。通过 git worktree add -b gh-pages ../gh-pages origin/gh-pages 进行设置。
额外奖励:如果您的
master
签出的子目录的内容是gh-pages
的内容,请使用 https://github.com/X1011/git-directory-deploy。The typical way is to switch branches:
git checkout master
if you want to work on master andgit checkout gh-pages
if you want to work ongh-pages
.Starting with git 2.5, you can have both branches checked out at the same time (in different directories). See https://github.com/blog/2042-git-2-5-including-multiple-worktrees-and-triangular-workflows. Setup via
git worktree add -b gh-pages ../gh-pages origin/gh-pages
.Bonus: If the content of a subdirectory of your
master
checkout is the content ofgh-pages
, use the script provided at https://github.com/X1011/git-directory-deploy.我使用这个
你可以看到工作版本 https://github.com/rofrol/ closeyoureyesnow/blob/master/build_and_deploy.sh
I use this
You can see working version https://github.com/rofrol/closeyoureyesnow/blob/master/build_and_deploy.sh