Hexo部署到github page
Tanwan

Hexo 部署到 GitHub Pages 指南

1. 创建 GitHub 仓库

在 GitHub 上新建一个与你用户名相同格式的仓库:

1
<你的用户名>.github.io

例如你的用户名是 tanwanme,那么仓库名应为:

1
tanwanme.github.io

2. 配置 Hexo 的部署信息

修改 d/Hexo/_config.yml 文件中的部署配置:

1
2
3
4
deploy:
type: git
repository: git@github.com:tanwanme/tanwanme.github.io.git
branch: master

请根据你的 GitHub 用户名替换上面的 tanwanme


3. 配置 SSH Key

使用你注册 GitHub 时的邮箱地址生成 SSH Key:

1
ssh-keygen -t rsa -C "6265911@qq.com"

系统会提示输入以下信息,全部直接按回车跳过即可:

1
2
3
Enter file in which to save the key (/Users/your_user_directory/.ssh/id_rsa): <回车>
Enter passphrase (empty for no passphrase): <回车>
Enter same passphrase again: <回车>

⚠️ 注意:Hexo 自动部署要求 SSH key 不设置密码。

启动 SSH agent 并添加 key:

1
2
3
ssh-agent -s
ssh-add ~/.ssh/id_rsa
clip < ~/.ssh/id_rsa.pub # macOS / Linux 用户请用 `cat ~/.ssh/id_rsa.pub`

将复制好的内容粘贴到 GitHub 的 SSH key 设置页面 中。


4. 配置 Git 用户信息

1
2
git config --global user.name "tanwanme"
git config --global user.email "10086@qq.com"

5. 部署 Hexo 博客到 GitHub

1
hexo clean && hexo g && hexo d

6. 手动上传本地项目到 GitHub 仓库

以下以上传 tanwanme/indigo 仓库为例:

克隆仓库到本地

1
2
git clone https://github.com/tanwanme/indigo.git git-upload
cd git-upload

将你要上传的内容放到 git-upload 文件夹中(保留 .github 文件夹)。

提交并推送

1
2
3
git add .
git commit -m "首次提交"
git push -u origin main

✅ 若提示输入用户名和密码,请使用你的 GitHub 账号信息。