gh-pages-deploy
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseGitHub Pages Deployment
GitHub Pages 部署
Deploy static frontend websites to GitHub Pages using the GitHub CLI.
使用GitHub CLI将静态前端网站部署到GitHub Pages。
Prerequisites
前置条件
- GitHub CLI () installed and authenticated
gh - Git installed
- A frontend project (HTML, CSS, JS) ready to deploy
- GitHub CLI () 已安装并完成身份验证
gh - Git 已安装
- 准备好要部署的前端项目(HTML、CSS、JS)
Deployment Workflow
部署流程
1. Initialize Git Repository (if needed)
1. 初始化Git仓库(如需要)
bash
git init
git add .
git commit -m "Initial commit"bash
git init
git add .
git commit -m "Initial commit"2. Create GitHub Repository
2. 创建GitHub仓库
bash
undefinedbash
undefinedCreate public repo (required for free GitHub Pages)
创建公开仓库(免费版GitHub Pages要求)
gh repo create <repo-name> --public --source=. --push
undefinedgh repo create <repo-name> --public --source=. --push
undefined3. Enable GitHub Pages
3. 启用GitHub Pages
bash
undefinedbash
undefinedEnable GitHub Pages from main branch root
从main分支根目录启用GitHub Pages
gh api repos/{owner}/{repo}/pages -X POST -f build_type=legacy -f source='{"branch":"main","path":"/"}'
Or for docs folder:
```bash
gh api repos/{owner}/{repo}/pages -X POST -f build_type=legacy -f source='{"branch":"main","path":"/docs"}'gh api repos/{owner}/{repo}/pages -X POST -f build_type=legacy -f source='{"branch":"main","path":"/"}'
或者针对docs文件夹:
```bash
gh api repos/{owner}/{repo}/pages -X POST -f build_type=legacy -f source='{"branch":"main","path":"/docs"}'4. Check Deployment Status
4. 检查部署状态
bash
undefinedbash
undefinedGet pages info
获取Pages信息
gh api repos/{owner}/{repo}/pages
gh api repos/{owner}/{repo}/pages
View deployment status
查看部署状态
gh api repos/{owner}/{repo}/pages/builds/latest
undefinedgh api repos/{owner}/{repo}/pages/builds/latest
undefined5. Get Site URL
5. 获取站点URL
The site will be available at:
https://<username>.github.io/<repo-name>/站点将在以下地址可用:
https://<username>.github.io/<repo-name>/Quick Deploy Script
快速部署脚本
For a complete deployment in one flow:
bash
undefined一键完成完整部署流程:
bash
undefinedVariables
变量
REPO_NAME="my-site"
REPO_NAME="my-site"
Initialize and commit
初始化并提交
git init
git add .
git commit -m "Initial commit"
git init
git add .
git commit -m "Initial commit"
Create repo and push
创建仓库并推送
gh repo create $REPO_NAME --public --source=. --push
gh repo create $REPO_NAME --public --source=. --push
Wait for push to complete, then enable pages
等待推送完成,然后启用Pages
sleep 2
OWNER=$(gh api user --jq '.login')
gh api repos/$OWNER/$REPO_NAME/pages -X POST -f build_type=legacy -f source='{"branch":"main","path":"/"}'
sleep 2
OWNER=$(gh api user --jq '.login')
gh api repos/$OWNER/$REPO_NAME/pages -X POST -f build_type=legacy -f source='{"branch":"main","path":"/"}'
Get the URL
获取URL
echo "Site will be at: https://$OWNER.github.io/$REPO_NAME/"
undefinedecho "Site will be at: https://$OWNER.github.io/$REPO_NAME/"
undefinedTroubleshooting
故障排除
- Pages not enabled: Ensure repo is public or you have GitHub Pro
- 404 error: Wait 1-2 minutes for deployment, check if index.html exists at root
- Build failed: Check GitHub Actions tab for errors
- Pages未启用:确保仓库是公开的,或者您拥有GitHub Pro权限
- 404错误:等待1-2分钟让部署完成,检查根目录是否存在index.html
- 构建失败:查看GitHub Actions标签页中的错误信息
Updating the Site
更新站点
After making changes:
bash
git add .
git commit -m "Update site"
git pushGitHub Pages will automatically rebuild.
修改内容后执行:
bash
git add .
git commit -m "Update site"
git pushGitHub Pages将自动重新构建站点。