github 创建gh-pages分支作为静态页面浏览地址

前端之家收集整理的这篇文章主要介绍了github 创建gh-pages分支作为静态页面浏览地址前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

先到github,找到项目主页面,创建gp-pages分支

在本地把项目克隆下来

git clone <你的项目地址>

完成以后cd 项目名称进入项目主目录

  • 本地创建分支,并且切换到该分支
    git checkout --orphan gh-pages
  • 删除里面的文件
    git rm -rf .
  • 之后再提交到分支

    git add .
    git commit -m 'push to branch'
    git push origin gh-pages
  • 一行行输入上述命令执行后会出现错误

    error: Failed to push some refs to 'git@github.com:*.git'
    hint: Updates were rejected because the tip of your current branch is behind
    hint: its remote counterpart. Integrate the remote changes (e.g.
    hint: 'git pull ...') before pushing again.
    hint: See the 'Note about fast-forwards' in 'git push --help' for details.
  • 使用强制push的方法,因为这是只做页面浏览地址代码存放,所以不用担心远程修改的情况
    git push -f origin gh-pages 使用强制push就可以成功了

到项目的github页面将gh-pages分支设置为github的GitHub Pages页面

  1. 点击Settings,找到左侧Options一栏(就是默认的),往下翻找到GitHub Pages在Source里面选择gh-pages branch,如果之前创建了gh-pages分支,这里应该默认选择了这个分支
  2. 下次提交时,正常提交就可以了,记得切换到gh-pages分支提交

    git add .
    git commit -m 'push to branch'
    git push origin gh-pages
原文链接:https://www.f2er.com/github/413273.html

猜你在找的GitHub相关文章