使用 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❤

相关推荐
计算机毕设定制辅导-无忧学长3 小时前
InfluxDB Flux 查询协议实战应用(二)
github
黄团团6 小时前
SpringBoot连接Sftp服务器实现文件上传/下载(亲测可用)
服务器·spring boot·github
九章云极AladdinEdu15 小时前
GitHub新手生存指南:AI项目版本控制与协作实战
人工智能·pytorch·opencv·机器学习·github·gpu算力
门前云梦20 小时前
ollama+open-webui本地部署自己的模型到d盘+两种open-webui部署方式(详细步骤+大量贴图)
前端·经验分享·笔记·语言模型·node.js·github·pip
SelectDB1 天前
Apache Doris Data Agent 解决方案:开启智能运维与数据治理新纪元
github·apache·mcp
lb29171 天前
git的使用,推送仓库github
git·github
桃白白大人1 天前
今日Github热门仓库推荐 第八期
人工智能·python·github
中东大鹅1 天前
SpringBoot创建项目的方式
java·spring boot·github
liangdabiao2 天前
LangGraph大法好:工作流编排框架,特别适合构建复杂的多步骤、有状态或协作式 AI 应用
后端·面试·github