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

相关文章

咱们在vscode中使用copilot的过程中,有可能会涉及到个人账号...
这篇文章给大家介绍怎么在GitHub上快速找到实用资源,内容非...
这篇文章主要介绍“github缓存穿透的解决方法是什么”,在日...
本篇内容介绍了“github线性回归怎么实现”的有关知识,在实...
怎样使用GitHub,很多新手对此不是很清楚,为了帮助大家解决...
今天小编给大家分享一下GitHub的高级搜索方法有哪些的相关知...