Github搭建个人博客全攻略

Github搭建个人博客全攻略


一、Github

Github是开发者的代码仓库,一个开源和分享社区。

本文前提是已注册github账号。


二、配置博客仓库

假设用户名为MyName

  1. 进入个人主页(https://github.com/用户名),选择Repositories,点击New
  2. Repository name填入MyName.github.io,即MyName/MyName.github.io,点击Create Repository

三、配置Git用户SSH密钥

  1. 安装GitTortoiseGit(后者添加环境变量)
  2. 打开git bash或命令行,执行ssh-keygen -t ed25519 -C "your_email@example.com"
  3. 默认在C:/Users用户名/.ssh里找到id_ed25519.pub(如步骤2使用rsa则是 id_rsa.pub),记事本打开复制里面的内容
  4. 右上角头像进入Settings,选择SSH and GPG Keys,点New SSH Key,随意填入Title,Key粘贴步骤3的密钥,点击Add SSH Key

四、Deploy Key or Token

博客Hexo部署用到Deploy Key或者Token的方式,选其一即可

方法一: Deploy Key

  1. 进入仓库页面的Setting,选择Deploy Key,点击Add Deploy Key
  2. 密钥生成步骤同步骤三,生成的时候选择保存其他的文件名,复制密钥内容到Key栏

方法二: Token

  1. 点个人头像,选择Setting,再选Developer Settings,Person access tokens,点tokens (classic),Generate new Token(classic),填写信息,Expiration默认30天,Select scopes勾选repo栏即可
  2. 点击Generate token,复制生成的Token下一步使用

五、Hexo

  1. 下载安装node,添加环境变量,配置依赖下载路径
  2. 安装hexo
shell 复制代码
npm install -g hexo-cli
npm install -g hexo-renderer-pug
npm install -g hexo-renderer-stylus
npm install -g hexo-deployer-git
  1. 建立博客,预览效果
shell 复制代码
# 新建博客目录
mkdir blog
# 初始化hexo项目
hexo init blog
# 安装依赖
cd blog
npm install 
# 生成静态文件
hexo generate
# 启动本地服务器 http://localhost:4000
hexo server
  1. Github部署
shell 复制代码
# blog/_config.yml, token或ssh key选一个repo配置,每个:号后面必须带一个空格
url: https://MyName.github.io/MyName.github.io
deploy: 
  type: git
  repo: https://上一步得到的token值@github.com/MyName/MyName.github.io
  # repo: git@github.com:MyName/MyName.github.io.git
  branch: master
  message: 

#执行部署
hexo deploy

六、 主题

shell 复制代码
git clone https://github.com/主题仓库地址.git themes/主题名

# 编辑_config.yml
theme: 主题名

七、 发布博文

shell 复制代码
hexo new post "How to build a bolg with Hexo on Github"
hexo clean
hexo generate
hexo deploy

登录https://MyName.github.io/即可查看发布的博文,更多知识点请上Hexo官网查阅。


八、参考链接

1 Generating a new SSH key and adding it to the ssh-agent

2 在 GitHub Pages 上部署 Hexo

相关推荐
小弥儿1 小时前
GitHub今日热榜 | 2026-09-04:Agent省 token 成今日主线
学习·开源·github
苏灿烤鱼4 小时前
给 AI Agent 装一个「会进化的大脑」:OpenViking 深度拆解
开源·github·agent
逛逛GitHub4 小时前
清华开源的 Agent 交互学习神器,又登上 GitHub 热榜了。
github
其实防守也摸鱼4 小时前
OpenClaw Windows 踩坑实战指南
运维·服务器·数据库·windows·github·copilot
小马9266 小时前
从单模型到多模型编排:GitHub HydraFusion 如何让编程 Agent 降本 36%-67%
人工智能·github
小弥儿7 小时前
GitHub今日热榜 | 2026-09-08:微软 markitdown 冲进前三
学习·microsoft·开源·github
蜡台8 小时前
超详细 GitHub Actions 自动发布部署教程
github·github page·github action
11路没有终点9 小时前
CI/CD 集成:GitHub Actions
ci/cd·github
右耳朵猫AI9 小时前
Github周刊2026W36 | Archify架构图生成、科研Agent技能库、VoiceStudio本地语音、MiniMind训练6400万参数
github
DeepAgent9 小时前
AI Agent 开发实战(13):GitHub 开源
开源·github·agent