git 分支:gh-pages

发布于 2024-10-13 15:22:52 字数 161 浏览 10 评论 0 原文

我在 GitHub 上有一个存储库。最近我发现了 GitHub 的页面,我想使用它们。
我想创建这个新分支,然后在需要时在 master 分支或 gh-pages 分支上提交。

我该怎么做?我是否必须在我的存储库中创建另一个文件夹?

I have a repo on GitHub. Recently I have discovered GitHub's pages and I want to use them.
I would like to create this new branch and then, when I need to, either commit on master branch or on gh-pages branch.

How can I do this? Do I have to create another folder inside my repo?

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

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

发布评论

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

评论(9

苏辞 2024-10-20 15:22:52

最新版本的 git 有一个替代 Chandru 解释的 git symbolic-ref 方法的方法。这避免了必须使用较低级别的命令。

git checkout --orphan gh-pages
git rm -rf .

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.

git checkout --orphan gh-pages
git rm -rf .
感情旳空白 2024-10-20 15:22:52

您可能会发现本教程很有用:

将 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

空心空情空意 2024-10-20 15:22:52

在本地克隆上,

git symbolic-ref HEAD refs/heads/gh-pages
rm .git/index 
git clean -fdx

然后,git checkout gh-pages 并编写页面。当您准备好发布页面时,git push origin gh-pages

On your local clone do,

git symbolic-ref HEAD refs/heads/gh-pages
rm .git/index 
git clean -fdx

Then, git checkout gh-pages and write your pages. git push origin gh-pages when you're ready to publish the pages.

自我难过 2024-10-20 15:22:52

您的问题还有另一种解决方案:忘记 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

抱着落日 2024-10-20 15:22:52

发布一个静态站点,如下所示:

git subtree push --prefix www origin gh-pages

其中 www 是静态文件所在的文档根目录。
您的静态站点现已上线:
https://[user_name].github.io/[repo_name]/

Publish a static site like this:

git subtree push --prefix www origin gh-pages

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]/

岁月流歌 2024-10-20 15:22:52

手动创建项目页面

手动为项目添加一组新页面非常简单
如果您习惯使用命令行 git,请执行此过程。

https://help.github.com/articles/creating-project-pages-手动

Creating Project Pages manually

Adding a new set of Pages for a project manually is a straightforward
process if you're used to using command-line git.

https://help.github.com/articles/creating-project-pages-manually

桃气十足 2024-10-20 15:22:52

您的 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, use git checkout --orphan gh-pages to create gh-pages and then delete all the unnecessary files using git 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

赢得她心 2024-10-20 15:22:52

典型的方法是切换分支:如果您想在 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 and git checkout gh-pages if you want to work on gh-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 of gh-pages, use the script provided at https://github.com/X1011/git-directory-deploy.

盛装女皇 2024-10-20 15:22:52

我使用这个

git push origin `git subtree split --prefix build`:$DEPLOY --force

你可以看到工作版本 https://github.com/rofrol/ closeyoureyesnow/blob/master/build_and_deploy.sh

I use this

git push origin `git subtree split --prefix build`:$DEPLOY --force

You can see working version https://github.com/rofrol/closeyoureyesnow/blob/master/build_and_deploy.sh

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