What is GitHub Pages?
GitHub Pages is a free static site hosting service built into GitHub. It serves HTML, CSS, and JavaScript directly from a repository.
Enable GitHub Pages
- Go to your repository Settings > Pages
- Under Source, select Deploy from a branch
- Choose
mainbranch and/ (root)folder - Click Save
- Your site will be live at
https://your-username.github.io/your-repo/
Using a Custom Build Folder
If your project builds to a dist/ folder (e.g., Vite):
- Build your project:
npm run build- Under Pages settings, choose
mainbranch and/docsfolder (renamedisttodocs), or use GitHub Actions for more control.
Deploy with GitHub Actions
For projects that need a build step, use a workflow:
- Go to Settings > Pages > Source and select GitHub Actions
- Create
.github/workflows/deploy.yml:
name: Deploy to GitHub Pages
on:
push:
branches: [main]
jobs:
deploy:
runs-on: ubuntu-latest
permissions:
pages: write
id-token: write
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
- run: npm install && npm run build
- uses: actions/upload-pages-artifact@v3
with:
path: dist
- id: deployment
uses: actions/deploy-pages@v4Custom Domain (Optional)
- Go to Settings > Pages > Custom domain
- Enter your domain (e.g.,
game.example.com) - Add a CNAME record in your DNS provider pointing to
your-username.github.io - Check Enforce HTTPS
Verify
After enabling, wait a few minutes then visit your Pages URL. Check the Actions tab if the deploy fails.