Learn how to host a static site from a private GitHub repository using GitHub Pages and map it to your custom domain. Ideal for developers using GitHub Pro or Team plans.
GitHub Pages for private repositories requires a paid plan. Visit GitHub Pricing and upgrade to Pro, Team, or Enterprise.
Your private repo should have the site files structured like:
index.html at the root or inside a /docs folderIn your repo:
main) and folder (/ or /docs)Still in the GitHub Pages settings, scroll to the Custom domain section and enter your domain (e.g., www.example.com). This will create a CNAME file in your repository automatically.
In your domain registrar dashboard (e.g., GoDaddy, Namecheap):
Allow time for DNS propagation (usually 15 mins to a few hours).
Once the custom domain is detected and DNS is ready, GitHub will issue a free SSL certificate. Enable "Enforce HTTPS" in the GitHub Pages settings to secure your site.
This step ensures your site loads over https:// with encryption, boosting SEO and security.
Donβt want to expose your entire private repo? Use GitHub Actions to build and push only your static files to a gh-pages branch:
main (private)npm run build)dist/) to a public gh-pages branchHereβs a basic GitHub Actions workflow:
name: Deploy Static Site
on:
push:
branches: [main]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Build Site
run: |
npm install
npm run build
- name: Deploy to gh-pages
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./dist
This keeps your source private while hosting only the output folder.
π SEO Tags: GitHub Pages Private Repo, Deploy with Custom Domain, GitHub Actions for Static Hosting, Force HTTPS GitHub Pages, Secure GitHub Custom Domain