连接到Github

配置git用户名和密码

git config --global user.name "用户名"
git config --global user.email "邮箱"

生成SSH Key

ssh-keygen -t rsa -C "邮箱"

SSH Key的位置:

Windows下: C/Users/Administrator/.ssh/id_ras.pub

MacOS: ~/.ssh/id_ras.pub

在Github添加SSH

验证SSH配置是否成功

ssh -T git@github.com

如果成功会提示:

Hi XXX! You've successfully authenticated, but GitHub does not provide shell access.

Github创建同名仓库

在github上创建一个和用户名相同的仓库,以.github.io结尾,<用户名>.github.io

仓库

Hexo配置

添加依赖

为了正常部署到github仓库,需要先安装hexo-deployer-git插件。在Hexo根目录输入

npm install hexo-deployer-git --save

如果没有安装的话会报错

INFO Validating config
ERROR Deployer not found: git

修改配置文件

修改Hexo根目录的_config.xml文件,修改deploy的内容:

deploy:
type: git
# 这里填写自己的github的名称即可
repository: ssh://git@github.com/用户名/用户名.github.io.git
# 注意这里,检查github的默认分支是 main 还是 master
brandh: main
messge:

部署到远程仓库

每次重新开一个新的终端都要重新连接git:

ssh -T git@github.com

执行下面的命令,然后再次进入Pages的链接https://用户名.github.io就可以看到你的博客了。

hexo generate # 也可以使用缩写  hexo g
hexo deploy # 缩写 hexo d

效果如下:

winstone.su

错误处理

  1. [remote rejected] HEAD -> master (protected branch hook declined)

错误信息:

deploy error

出现这种问题的原因是,github仓库的branch添加了protection rules,在当前仓库的Settings –> Branches 删除 Branch protection rules

Delte Branch protection Rules