按照以下步骤将网站发布到 GitHub Pages:
- 打开 PowerShell 或命令提示符
- 切换到项目目录:
cd "D:\Vibe coding\Pytorch教程博客" - 初始化 Git 仓库:
git init
- 添加所有文件:
git add . - 创建初始提交:
git commit -m "Initial commit: PyTorch tutorial blog website"
- 登录 GitHub
- 点击右上角的 "+" 号,选择 "New repository"
- 仓库名称建议:
pytorch-tutorial-blog或pytorch-blog - 重要:仓库名称必须为
你的用户名.github.io格式才能使用 GitHub Pages- 例如:如果你的用户名是
yourusername,仓库名应为yourusername.github.io
- 例如:如果你的用户名是
- 选择 Public(公开)
- 不要勾选 "Initialize this repository with a README"
- 点击 "Create repository"
在项目目录中执行以下命令(将 YOUR_USERNAME 替换为你的 GitHub 用户名):
git remote add origin https://github.com/YOUR_USERNAME/YOUR_USERNAME.github.io.git
git branch -M main
git push -u origin main如果仓库名不是 用户名.github.io 格式,使用:
git remote add origin https://github.com/YOUR_USERNAME/REPO_NAME.git
git branch -M main
git push -u origin main- 在 GitHub 仓库页面,点击 "Settings"(设置)
- 在左侧菜单中找到 "Pages"
- 在 "Source" 部分:
- 选择分支:
main - 选择文件夹:
/ (root)
- 选择分支:
- 点击 "Save"(保存)
等待几分钟后,你的网站将在以下地址可用:
https://YOUR_USERNAME.github.io- 或
https://YOUR_USERNAME.github.io/REPO_NAME(如果仓库名不是用户名.github.io)
每次更新网站后,执行:
git add .
git commit -m "更新网站内容"
git pushGitHub Pages 会自动更新(通常需要几分钟)。
如果推送时要求输入用户名和密码,可以使用 Personal Access Token:
- GitHub → Settings → Developer settings → Personal access tokens → Tokens (classic)
- 生成新 token,勾选
repo权限 - 使用 token 作为密码
- 检查仓库设置中的 Pages 是否已启用
- 确认分支和文件夹设置正确
- 等待 5-10 分钟让 GitHub 完成部署
- 检查 Actions 标签页查看是否有构建错误
如果你想使用自己的域名:
- 在仓库 Settings → Pages 中添加你的域名
- 在你的域名 DNS 设置中添加 CNAME 记录指向
YOUR_USERNAME.github.io