git 分支:gh-pages
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4750520/
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
git branch: gh-pages
提问by rubik
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.
我在 GitHub 上有一个仓库。最近我发现了 GitHub 的页面,我想使用它们。
我想创建这个新分支,然后,当我需要时,要么在master
分支上提交,要么在分支上提交gh-pages
。
How can I do this? Do I have to create another folder inside my repo?
我怎样才能做到这一点?我是否必须在我的 repo 中创建另一个文件夹?
采纳答案by Chris Jacob
You might find this tutorial useful:
您可能会发现本教程很有用:
将 GitHub Pages 的“gh-pages”分支和“master”分支设置为父项目文件夹(“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 ^_^
对我来说,这种方法似乎比git checkout gh-pages
每次要编辑 gh-pages 内容时都执行一个更简单。让我知道你的想法^_^
Edit:I updated the tutorial link - thanks @Cawas. The old tutorial (not recommended) was https://gist.github.com/825950
编辑:我更新了教程链接 - 谢谢@Cawas。旧教程(不推荐)是https://gist.github.com/825950
回答by Arrowmaster
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 可以替代git symbolic-ref
Chandru 解释的方法。这避免了必须使用较低级别的命令。
git checkout --orphan gh-pages
git rm -rf .
回答by Chandra Sekar
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.
然后,git checkout gh-pages
写你的页面。git push origin gh-pages
当您准备好发布页面时。
回答by Rsh
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.
您的问题还有另一种解决方案:忘记gh-pages
和分支;将您应该提供的静态文件放在/docs
目录中,然后转到您的项目设置并告诉 github 提供/docs
内容。
For more information take a look at this
有关更多信息,请查看此
回答by Jonas Ellehauge
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]/
www
静态文件所在的文档根目录在哪里。您的静态网站现在位于:
https://[user_name].github.io/[repo_name]/
回答by mockee
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.
手动创建项目页面
如果您习惯于使用命令行 git,手动为项目添加一组新页面是一个简单的过程。
https://help.github.com/articles/creating-project-pages-manually
https://help.github.com/articles/creating-project-pages-manually
回答by Saba Ahang
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/
您的 gh-pages 和 master 分支是否具有完全相同的文件夹结构?如果是这种情况,你为什么还要有两个分支?只需维护一个 gh-pages 分支!但是,如果出于某种原因您希望两个分支不断同步,那么您最好的选择是使用git rebase
. 见这里: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/
您还可以仅从 master 中挑选您需要的文件,并使用git checkout
. 见这里:
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.
不得不解决同样的问题后,我发现 gh-pages 通常最终会拥有与 master 不同的代码库。换句话说,gh-pages 应该只包含项目的 dist/build/publish 文件夹的内容,而 master 将包含您的配置文件、未压缩的脚本和样式等。
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/
我的建议是创建 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-manually/
Good luck
祝你好运
回答by koppor
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
.
典型的方法是切换分支:git checkout master
如果你想在 master 上工作,git checkout gh-pages
如果你想在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
.
从 git 2.5 开始,您可以同时检出两个分支(在不同的目录中)。请参阅https://github.com/blog/2042-git-2-5-include-multiple-worktrees-and-triangular-workflows。通过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.
奖励:如果您master
结帐的子目录的内容是 的内容gh-pages
,请使用https://github.com/X1011/git-directory-deploy提供的脚本。
回答by rofrol
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
你可以看到工作版本https://github.com/rofrol/closeyoureyesnow/blob/master/build_and_deploy.sh