如何在 GitHub 页面 gh-pages 上托管我的应用程序



我正在处理的应用程序有以下设置,我想使用 gh-pages 在 github 上托管该应用程序。 在这里,我希望实现这一目标。

UserName@PC1 ~/GitHub/ud989-retain
$ ls
css  index.html  js
UserName@PC1 ~/GitHub/ud989-retain
$ git status
# On branch master
nothing to commit (working directory clean)
UserName@PC1 ~/GitHub/ud989-retain
$ git branch
* master

以下是我为将我的页面托管在 Gihub GH-pages 上所做的工作

# create the gh-pages branch
git branch gh-pages   
# think this copies all files from master/origin to gh-pates(remotely and locally I think?)
git push origin gh-pages
# this shows the branches available(master and gh-pages and you should be on master)
git branch
# change to the gh-pages branch
git checkout gh-pages
#get the status of your repo, it should be upto date 
git status
# this shows the branches available(master and gh-pages and you should be on gh-pages)
git branch
# create a .nojekyll, not sure what this does exactly but it is required 
touch .nojekyll
# you should be able to see your .nojekyll
ls -a
# now add your .nojekyll for committing, not sure why i don't have to commit the others but maybe they are done with the git push origin gh-pages
git add .nojekyll
# commit the file with a comment 
git commit -a -m "adding .nojekyll file"
# this gives the remote URLs, not required but just checking they are there
git remote -v
# push to your remote repo, and I should be able to view my page online 
git push origin gh-pages

因此,最终结果将是您的 github 帐户、母版和 gh 页面中的 2 个分支,它们应该具有相同的文件。然后,您应该获得指向页面托管位置的链接。这可以在 git 中心帐户的设置中找到。

编辑1 完成上述操作后,如果您使用存储库访问 github 页面并选择设置,在 Gihub 页面下您应该拥有例如:GitHub 页面 您的网站发布在 http://hattricknz.github.io/ud989-retain.

注意:我已经在各个地方搜索了这个,但我找不到它的文档,或者我总是遇到问题。所以在这里,我希望这能很好地参考我。也可能有其他/更好的方法来做我不知道的类似事情。


编辑2

只是重新审视这一点:我有一个存储库,我刚刚将其推送到 github,其中包含一个看起来像这样的主分支:

$ ls
assets  index.html  README.md  robots.txt

现在我想在github上发布它。我正要从我的笔记中遵循这一点

git branch gh-pages
git push origin gh-pages
git branch
git checkout gh-pages
git status
git branch
touch .nojekyll
ls -a
git add .nojekyll
git commit -a -m "adding .nojekyll file"
git remote -v
git push origin gh-pages

但我只是做了以下操作:然后转到我的存储库的设置,它说Your site is published at .... 所以也许这就是我需要做的?我会再次光顾...

git branch gh-pages
git push origin gh-pages
git branch
git checkout gh-pages
你应该

检查gh-pages,它提供了分步文档

git clone repo.git
cd repo
git branch --orphan gh-pages

添加您的 HTML/CSS/JS 文件...而不是提交和推送。

git push origin gh-pages

最新更新