部署到 GitHub Pages
前置要求
- GitHub 账号
- 安装 Git
- 安装 Hugo(Extended 版本)
本地预览
| |
部署步骤
创建 GitHub 仓库
- 仓库名:
yourusername.github.io(这是用户站点) - 或者任意名称(这是项目站点)
- 仓库名:
推送代码
1 2 3 4 5 6git init git add . git commit -m "Initial commit" git branch -M main git remote add origin https://github.com/yourusername/yourusername.github.io.git git push -u origin main配置 GitHub Pages
- 进入仓库 Settings → Pages
- Source 选择 “Deploy from a branch”
- Branch 选择 “gh-pages”
- 保存
等待部署
- GitHub Actions 会自动运行
- 大约 1-2 分钟后即可访问
自定义域名(可选)
- 在
static/目录下创建CNAME文件 - 文件内容为你的域名,如
blog.yourdomain.com - 在域名服务商添加 CNAME 记录指向
yourusername.github.io
你的博客已经 ready,去写作吧!