Git Notes
GitHub Pages is a free static site hosting service provided by GitHub that publishes websites directly from a repository. It is perfect for project...
GitHub Pages is a free static site hosting service provided by GitHub that publishes websites directly from a repository. It is perfect for project documentation, personal portfolios, blogs, and any static website. The best part is that deployment happens automatically when you push to the configured branch — no separate hosting setup, no server management, no monthly bills.
What GitHub Pages Supports
GitHub Pages serves static content — HTML, CSS, JavaScript, images, and fonts. It does not run server-side code (no Node.js, Python, or PHP). However, with static site generators and frontend frameworks that produce static builds, you can create sophisticated websites.
Common uses for GitHub Pages:
- Personal portfolio websites
- Project documentation sites
- Technical blogs (using Jekyll, Hugo, or Gatsby)
- Landing pages for open source projects
- Frontend-only web applications (React, Vue, Angular builds)
Setting Up GitHub Pages
Method 1: Repository Settings
- Go to your repository on GitHub
- Navigate to Settings → Pages
- Under "Source," select a branch (usually
mainorgh-pages) - Choose the root folder (
/or/docs) - Click Save
Your site will be available at https://username.github.io/repository-name/.
Method 2: GitHub Actions Workflow
For more control over the build process:
Deploying a React Application
Build your React app and deploy the output:
# In your React project
npm run build
# This creates a 'build' or 'dist' folder with static filesConfigure your package.json:
{
"homepage": "https://username.github.io/my-react-app",
"scripts": {
"predeploy": "npm run build",
"deploy": "gh-pages -d build"
}
}Install the deployment package:
npm install --save-dev gh-pages
npm run deployThis pushes your build folder to the gh-pages branch, which GitHub Pages serves.
Custom Domains
You can use your own domain name instead of the default github.io URL:
- Purchase a domain from a registrar
- Add a CNAME file to your repository containing your domain:
- Configure DNS records with your registrar:
| Type | CNAME |
| Name | www |
| Value | username.github.io |
| Type | A |
| Name | @ |
- Enable HTTPS in repository settings (GitHub provides free SSL certificates)
Jekyll Integration
GitHub Pages has built-in support for Jekyll, a static site generator:
# Create a simple Jekyll site
mkdir my-blog && cd my-blog
git init
# Create _config.yml
cat > _config.yml << EOF
title: My Developer Blog
description: Writing about code and technology
theme: minima
EOF
# Create your first post
mkdir _posts
cat > _posts/2024-01-15-hello-world.md << EOF
Welcome to my blog! This is my first post.
EOF
git add .
git commit -m "Initial Jekyll site"
git push origin mainGitHub automatically builds Jekyll sites — no GitHub Actions workflow needed.
Troubleshooting Common Issues
Site shows a 404:
- Verify the source branch and folder in Settings → Pages
- Check that
index.htmlexists in the root of your published folder - Wait a few minutes — deployment is not instant
CSS and JavaScript not loading:
- Check your base URL. For project pages, paths must be relative or include the repository name
- In React: set
homepageinpackage.json - In Vite: set
base: '/repo-name/'invite.config.js
Build failures:
- Check the Actions tab for build logs
- Ensure your dependencies are properly listed in
package.json - Test the build locally before pushing:
npm run build
Custom domain not working:
- DNS propagation takes up to 48 hours
- Verify CNAME file is in the published branch
- Check DNS records with:
dig www.yourdomain.com
Environment Variables for Builds
For builds that need environment variables:
steps:
- name: Build
run: npm run build
env:
REACT_APP_API_URL: https://api.production.com
VITE_GA_ID: G-XXXXXXXXXXNever put secrets in frontend builds — everything in the output is visible to users.
Key Takeaways
GitHub Pages provides free, automated hosting for static websites directly from your repository. It supports custom domains with HTTPS, integrates with static site generators, and deploys automatically on push. For any project that produces static output — documentation, portfolios, blogs, or frontend applications — GitHub Pages eliminates the need for external hosting services and keeps your deployment workflow entirely within GitHub.
Exam Focus
Revise definitions, diagrams, examples, and short-answer points for GitHub Pages Deployment.
Interview Use
Prepare one clear explanation, one practical example, and one common mistake for this Git & GitHub topic.
Search Terms
git-github, git & github, git, github, deployment, pages, github pages deployment
Related Git & GitHub Topics