I am creating a GitHub repository that is a website and has as its entry point the index.html
file. I would like to put it in a src/
folder and publish it with GitHub pages. Unfortunately, GitHub offers me either to create a docs/
folder (which contains the documentation normally), or to place the index.html
at the root of the project.
How can I deploy the website from a folder other than docs?
Repo link: https://github.com/timotheeMM/snake-game
You can use the peaceiris/actions-gh-pages
github action to deploy a folder of your choice to the gh-pages
branch. Github will then deploy the contents of this branch.
On your main branch, create a .github/workflows/web.yml
file with the following content:
name: Deploy website
on:
push:
branches:
- main
pull_request:
jobs:
deploy:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
- name: Deploy
uses: peaceiris/actions-gh-pages@v3
if: github.ref == 'refs/heads/main'
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./src # deploy src folder
In the Pages
tab of your repository settings, set the deploy branch to gh-pages
:
Each time you push a commit to the main
branch, the gh-pages
branch gets automatically updated with only the contents of the src
folder:
Your website will then be available at https://<username>.github.io/<repo-name>/