使用 GitHub Pages 快速部署静态网页

文章目录

概要

GitHub Pages 是 GitHub 提供的免费静态网页托管服务,支持直接从 GitHub 仓库中部署 HTML、CSS、JavaScript 等前端文件,适用于个人博客、项目展示页面等。

一、新建仓库

  1. 登录 GitHub,点击右上角 "+" → "New repository"
  2. 仓库名格式:<用户名>.github.io(例如:yourusername.github.io)【必须符合这种格式】
  3. 设为 Public(Private 仓库需要付费才能使用 Pages)
  4. 点击 "Create repository"

二、上传网页文件

注意:

  • yourusername 替换成自己的名称
  • 推送代码到远程仓库:git push <远程仓库名> <本地分支名>:<远程分支名>

方法一

  1. 克隆仓库到本地:

    bash 复制代码
    git clone https://github.com/yourusername/yourusername.github.io.git
    cd yourusername.github.io
  2. 添加你的网页文件(HTML、CSS、JS等)

    • 至少需要一个 index.html 作为首页
  3. 提交更改:

    bash 复制代码
    git add .
    git commit -m "描述信息"
    git push origin main:master

方法二

三、启用 GitHub Pages

一般前面操作对了就可以直接访问 https://yourusername.github.io 查看你的网站。

  1. 在仓库页面,点击 "Settings" → "Pages"
  2. 在 "Source" 部分,选择分支(通常为 mainmaster
  3. 点击 "Save"
  4. 等待几分钟,访问 https://yourusername.github.io 查看你的网站

❤觉得有用的可以留个关注ya❤

相关推荐
wangruofeng6 小时前
opencodex 解锁 Codex 任意模型,一个本地代理打通 Claude/Kimi/GLM/DeepSeek
llm·github·openai
一点一木8 小时前
从60首歌到1个网站:输入你的故事,还你一首歌
前端·github
刘较瘦_13 小时前
AI 开发中的 Git Submodule 父子仓库模式:前后端分仓管理与协作实践
前端·github
DeMinds15 小时前
内容没有丢,我为什么总在重新整理?|DeMinds 如何让工作接着继续
ios·github·markdown
寒水馨16 小时前
macOS下载、安装openclaw-v2026.7.1(附安装包OpenClaw-2026.7.1.dmg)
macos·大模型·github·开源软件·ai助手·openclaw·gpt-5.6
徐小夕16 小时前
花了3天,我写了一款开源AI公众号编辑器
前端·vue.js·github
CCPC不拿奖不改名1 天前
大模型推理架构与开源生态知识整理
数据库·windows·python·架构·langchain·开源·github
redreamSo2 天前
一天涨 1800 星的 GitHub 榜首:AI 编程瓶颈变成了 token
人工智能·开源·github
小弥儿2 天前
GitHub今日热榜 | 2026-07-20:AI Agent 知识体系迎来系统化梳理
学习·开源·github