使用 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" 部分,选择分支(通常为 main 或 master)
  3. 点击 "Save"
  4. 等待几分钟,访问 https://yourusername.github.io 查看你的网站

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

相关推荐
wflynn13 小时前
GitHub 今日推荐|univer:可嵌入 Web 应用的开源 Office 引擎
typescript·开源·github·doc·collaboration·board
dong_junshuai14 小时前
每天一个开源项目#163 Ghost Downloader:分块下载为何不用合并
github
网易云信14 小时前
AI 写 IM 集成总用错 API?用云信 AI Skills 把文档接进开发流程
github
猛码象限15 小时前
【GitHub 周报】换血八成,注意力从造 Agent 转向管 Agent
github·业界资讯
逛逛GitHub15 小时前
很多人想把《GTA 6》移植到 PC 上,这 4 个 GitHub 项目在努力。
github
逛逛GitHub15 小时前
谷歌 Chrome 团队出手了,GitHub 上获 1W 的 Star 了。
github
秋千易20 小时前
评测通过率 0.5,阈值一改就绿:跑分器先写三种退出码
github
答案answer20 小时前
从0-1在高德地图上搭建一个智慧仓库数字孪生场景
github
徐小夕21 小时前
折腾一年,我们正式发布 JitOffice:一款跑在浏览器里的 AI Office
前端·vue.js·github
zhensherlock2 天前
Protocol Launcher 系列:CodeHub 移动端 GitHub 协作利器
前端·javascript·typescript·node.js·自动化·github·js