You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过GitHub Pages从非docs/文件夹(如src/)部署网站?

如何从GitHub仓库的src/文件夹部署GitHub Pages网站

方法一:使用GitHub Actions自动部署(推荐)

这是最灵活的方案,支持指定任意文件夹作为部署源,步骤如下:

  1. 创建工作流配置文件
    在仓库中新建路径 .github/workflows/deploy.yml,填入以下内容:
name: Deploy to GitHub Pages

on:
  push:
    branches: ["main"]  # 替换为你的主分支名称,比如master
  workflow_dispatch:

permissions:
  contents: read
  pages: write
  id-token: write

jobs:
  deploy:
    environment:
      name: github-pages
      url: ${{ steps.deployment.outputs.page_url }}
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v4

      - name: Setup Pages
        uses: actions/configure-pages@v4

      - name: Upload artifact
        uses: actions/upload-pages-artifact@v3
        with:
          path: './src'  # 指定要部署的src文件夹路径

      - name: Deploy to GitHub Pages
        id: deployment
        uses: actions/deploy-pages@v4
  1. 配置GitHub Pages部署源
  • 打开仓库的「Settings」页面,找到「Pages」选项卡
  • 在「Build and deployment」的「Source」下拉菜单中选择「GitHub Actions」,保存设置

之后每次向主分支推送代码,GitHub Actions都会自动把src/文件夹内的内容部署到GitHub Pages。

方法二:利用Jekyll配置(仅适用于Jekyll项目)

如果你的项目基于Jekyll,可在仓库根目录创建 _config.yml 文件,添加以下配置:

source: src

然后在GitHub Pages设置中选择「Deploy from a branch」,分支选你的主分支,文件夹选「/(root)」即可,Jekyll会自动将src/作为网站源目录处理。

内容的提问来源于stack exchange,提问作者Tim240

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.03 09:49:59