0x01 创建github域名以及空间
进入www.github.com 后登录(如没有账号需要注册账号登录),新建Repositories,命名为[github用户名.github.io],设为公有仓。

0x02 git,nodejs,hexo 安装
git下载地址:https://git-scm.com/download/win
nodejs下载地址:
下载后,一路下一步安装,安装完成后,点开桌面Git bash或者随便找个文件夹点右键打开git bash类似Linux终端,安装完成后才能在git bash中安装hexo。
#打开git bash,执行命令安装hexo
npm install -g hexo-cli
0x03 github ssh与hexo博客 配置
#在git bash中执行生成密钥用于连接github
ssh-keygen -t rsa -C "ex@ex.com"
回车后会在windows当前登录目录下,在C:usersxxxssh目录生成id_rsa与id_rsa.pub密钥文件,到github页面找到设置–SSH Keys。



用记事本将id_rsa.pub打开,复制里面所有内容到此处,使用git bash ssh连接到github,创建hexo目录,以及后续操作。
#使用git bash命令行连接到github
ssh -T git@github.com
$ ssh -T git@github.com
Hi xxx! You've successfully authenticated, but GitHub does not provide shell access.
#git bash新建博客文件夹
hexo init xxx@github.io # [与github中新建仓库名一致]
博客主题安装
进入博客文件夹,安装博客主题,此处安装next,可自选其他主题。
#进入git bash执行
cd webpoplayer@github.io
git clone https://github.com/iissnan/hexo-theme-next themes/next
Cloning into 'themes/next'...
remote: Enumerating objects: 12037, done.
Receiving objects: 6% (759/12037), 148.01 KiB | 37.00 KiB/s
... ... #直到安装结束
# Site
title: 呆呆的初学者 #网站名
subtitle: ''
description: '@Webpoplayer,呆呆的初学者' #网站描述文字
keywords:
author: John Doe
language: en
timezone: 'Asia/Shanghai' #时区设置
... ...
# Deployment
## Docs: https://hexo.io/docs/one-command-deployment
deploy:
type: git
repo: https://github.com/[github用户名]/xxx.github.io.git
branch: master #添加此行
---
title: hello,world~
---
保存到当前目录,注意后缀为md。
#进入git bash执行
npm install hexo-deployer-git --save
#在git bash 中执行命令
hexo clean && hexo g && hexo d
#hexo clean 清除缓存
#hexo g 生成静态页面
#hexo s 启动服务预览
#hexo d 开始部署
后续的文章更新,在xxx.github.io/source/_posts 目录中新建md后缀格式文件,编写即可,编写完成后在git bash中使用以上命令同步到github中即可。
首先,你如果自己拥有域名,可以在域名新建两条CNAME解析记录,WWW与@ 均解析到xxx.github.io,生效时间看当前域名厂商。
#进入git bash依次终端执行
touch CNAME #新建CNAME文件
vi CNAME #编辑CNAME文件
xxx.com #你拥有的域名,保存退出vi
待域名解析生效后,即可输入xxx.com 进入你的博客了。
0x05 效果预览

0x06 git 修改上传者信息
当你通过命令行同步博客发布文章时,发布后在github仓库中发现commit的用户信息不对,想修改的时候,可以通过如下进行修改。
#修改提交者信息
git init #先执行,再一条条执行以下
git filter-branch --env-filter '
OLD_EMAIL="old@mail.com" #旧的邮件信息
CORRECT_NAME="newname" #新的使用者名称
CORRECT_EMAIL="new@mail.com" #新的邮件地址
if [ "$GIT_COMMITTER_EMAIL" = "$OLD_EMAIL" ]
then
export GIT_COMMITTER_NAME="$CORRECT_NAME"
export GIT_COMMITTER_EMAIL="$CORRECT_EMAIL"
fi
if [ "$GIT_AUTHOR_EMAIL" = "$OLD_EMAIL" ]
then
export GIT_AUTHOR_NAME="$CORRECT_NAME"
export GIT_AUTHOR_EMAIL="$CORRECT_EMAIL"
fi
' --tag-name-filter cat -- --branches --tags
git push --force --tags origin 'refs/heads/*' #强制更新仓库
#全局修改默认git提交者信息
git config --global user.name "username"
git config --global user.email user@xx.com