← Back to Git Course | Chapter 9: CI/CD & DevOps | Lesson 5 of 5

GitHub Pages

GitHub Pages is like a free bulletin board where you pin your website files and GitHub shows them to the whole world.
Syntax
bash
git push origin branch_name
git checkout -b gh-pages
git push origin gh-pages

What is GitHub Pages

GitHub Pages is a free static-site host built directly into every GitHub repository -- push HTML, CSS, and JavaScript to a designated branch or folder, and GitHub serves it at a public URL with no separate hosting account or server to manage.

Example: What is GitHub Pages

bash
git push origin main
# enable Pages in repository Settings, served at username.github.io/repo

The gh-pages Branch Convention

Many older projects and static-site generators publish to a dedicated gh-pages branch, kept separate from main so the built output never mixes with source code history -- tools like gh-pages (npm) or Jekyll automate pushing built files there.

Example: The gh-pages Branch Convention

bash
git checkout -b gh-pages
git push origin gh-pages

Actions-Based Deployment

Modern GitHub Pages setups typically use a GitHub Actions workflow that builds the site (e.g. running a static-site generator) and deploys the output automatically on every push to main, replacing the older manual gh-pages-branch workflow entirely.

Example: Actions-Based Deployment

bash
# .github/workflows/deploy.yml
on:
  push:
    branches: [main]
jobs:
  deploy:
    steps:
      - run: npm run build

Custom Domains

A GitHub Pages site can be served from your own domain instead of the default github.io URL by adding a CNAME file to the published branch and pointing your domain's DNS records at GitHub's servers.

Example: Custom Domains

bash
echo "www.example.com" > CNAME
git add CNAME
git commit -m "Add custom domain"

Troubleshooting a Pages Build

When a Pages deployment fails or shows a 404, the two most common causes are the wrong publish source selected in repository settings, or an index.html missing from the root of the published branch/folder -- checking the Actions tab's build log is usually the fastest way to diagnose it.

Example: Troubleshooting a Pages Build

bash
ls index.html
# check Settings > Pages for the correct publish source
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
Common Mistakes
  1. Publishing from the wrong branch or folder, so the site shows a 404; check the Pages source in the repository settings.
  2. Using absolute paths like /style.css in a project site, which breaks because it is served under /repo/.
  3. Expecting Pages to run server code like PHP or Python, when it only serves static files.
Chapter Summary
  • GitHub Actions and CI/CD pipelines automate building and testing code.
  • Docker integration and deployment workflows help ship applications.
  • GitHub Pages hosts static sites directly from a repository.
🔒

Chapter Quiz — Complete all 5 topics to unlock

0/5 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.