跳到主要内容
版本:2026 HER WAKA 活动

部署你的网站

你的网站在电脑上已经可以运行了。现在让我们把它发布到互联网 —— 免费。

你的网站地址将是 yourusername.github.io/my-website —— 把 yourusername 替换为你的 GitHub 用户名。

  1. 创建 GitHub 仓库并推送代码

    确保 Gemini CLI 正在你的 my-website 文件夹中运行。然后说出或输入这条提示词:

    说出或复制此提示词
    I want to put this website on GitHub so I can host it with GitHub
    Pages for free. Please do the following:
    1. Initialize a git repository in this folder
    2. Create a new PUBLIC repository on my GitHub account called "my-website"
    3. Add all my files and make the first commit
    4. Push everything to the new GitHub repository
    5. Show me the URL of the repository when you're done

    I already have git and the GitHub CLI (gh) installed and logged in.

    仓库必须是公开的才能使用免费的 GitHub Pages 托管。这是个人网站的标准做法 —— 你的代码将对其他人可见,就像互联网上大多数网站一样。

  2. 启用 GitHub Pages

    在 Gemini CLI 中说出或输入这条提示词:

    说出或复制此提示词
    Now I want to enable GitHub Pages for this repository so my website
    goes live on the internet. Please:
    1. Enable GitHub Pages, deploying from the main branch
    2. The website files are in the root of the repository (not a subfolder)
    3. Tell me the URL where my website will be available
    4. Check if the deployment is successful

    My GitHub username is [your-username].

    [your-username] 替换为你真实的 GitHub 用户名。

  3. 等待并验证

    GitHub 需要 1–3 分钟来构建和发布你的网站。

    1. 等待约 2 分钟
    2. 打开浏览器并访问:https://yourusername.github.io/my-website
    3. yourusername 替换为你的 GitHub 用户名

    看到 404 页面? 不用担心 —— 再等一分钟后刷新。首次部署最长需要 3 分钟。

    你也可以让 Gemini CLI 帮你检查:

    说出或复制此提示词
    Can you check if my GitHub Pages deployment is complete? Please check
    the deployment status of my repository and tell me when my website
    is live. Also give me the exact URL to visit.
  4. 在 GitHub 上验证

    1. 在 GitHub 上进入你的仓库
    2. 查看最新提交旁边的绿色对勾 —— 这表示部署成功
    3. 前往 SettingsPages 查看你的网站 URL
    如何找到你的网站 URL
    1. 前往 github.com/yourusername/my-website
    2. 点击 Settings(齿轮图标标签页)
    3. 点击左侧边栏的 Pages
    4. 你的网站 URL 显示在顶部:https://yourusername.github.io/my-website

故障排除

我看到 404 错误
  • 等待几分钟 —— 首次部署最长需要 3 分钟
  • 确保 URL 正确:https://yourusername.github.io/my-website
  • 检查你的仓库根目录(不是子文件夹)中是否有 index.html 文件
  • 前往 Settings → Pages,确认 source 设置为 main 分支和 / (root)
找不到仓库
  • 确保仓库是公开的,不是私有的
  • 检查拼写 —— URL 是区分大小写的
  • 在终端运行 gh repo list 查看你的仓库列表
Settings 中看不到 Pages 选项
  • GitHub Pages 在免费套餐中仅适用于公开仓库
  • 如果你的仓库是私有的,前往 Settings → General → Danger Zone → Change visibility 改为公开

你的网站已上线! 把链接分享给朋友、家人,以及发到 LinkedIn 上。这是你自己做的!

想继续改进你的网站?前往继续探索,获取更多想法、更新说明和下一步建议。