GitHub Pages 部署指南(实测版)

    1. 注册账号,在 GitHub 创建空仓库

    打开 https://github.com/new

    • Repository name: gtit
    • 选 Public(免费 Pages 必须公开)
    • 什么都不勾选,直接点 Create repository

    2. 生成 Token(推送认证用)

    打开 https://github.com/settings/tokens/new

    • Note: gtit-deploy
    • Expiration: 30 days
    • 勾选 repo(Full control of private repositories)
    • 点击 Generate token → 立即复制(只显示一次)
    
    格式: ghp_************************************

    这个 Token 相当于密码,不要公开。用完可删除重建。

    3. 推送本地代码到仓库

    在本地站点目录执行:

    git init
    git config user.emAIl "你的邮箱"
    git config user.name "你的名字"
    git add .
    git commit -m "Initial commit"
    
    git remote add origin https://github.com/devstackweb/git.git
    git remote set-url origin https://ghp_************************************@github.com/devstackweb/git.git
    git branch -M main
    git push -u origin main

    把 ghp_************************************ 换成你复制的 Token。

    4. 启用 GitHub Pages

    打开 https://github.com/devstackweb/git/settings/pages

    • Source: Deploy from a branch
    • Branch: main / (root)
    • 点击 Save

    等 1-3 分钟,站点自动部署。

    5. 绑定自定义域名

    5.1 GitHub 侧

    在 Pages 设置的 Custom domain 填入 如 git.*.com,点 Save。勾选 Enforce HTTPS。

    5.2 DNS 解析后台

    添加 CNAME 记录:

    记录类型主机记录记录值
    CNAMEgitdevstackweb.github.io

    等 5-30 分钟,回到 GitHub 点 Check again。

    6. 阻止搜索引擎收录(可选)

    所有 HTML 的 <head> 里加:

    <meta name="robots" content="noindex, nofollow">

    根目录放 robots.txt:

    User-agent: *
    Disallow: /

    7. 后续更新

    改完文件后推送:

    git add .
    git commit -m "Update description"
    git push origin main

    等 1-3 分钟自动上线。