Deploy to GitHub Pages: A Step-by-Step Guide

Ann Jul 09, 2026

Deploying your project to GitHub Pages can make it accessible to the world, showcase your work, and even serve as a static website host. Here's a step-by-step guide on how to achieve this.

a laptop computer sitting on top of a wooden desk next to a cup of coffee
a laptop computer sitting on top of a wooden desk next to a cup of coffee

Before we dive in, ensure you have a GitHub account, your project is in a repository, and you're familiar with basic Git commands. Let's get started!

How to Host a Website for Free Using GitHub Pages
How to Host a Website for Free Using GitHub Pages

Preparing Your Repository

First, let's ensure your repository is ready for GitHub Pages.

Level Up Your Coding with GitHub: A Beginner's Guide
Level Up Your Coding with GitHub: A Beginner's Guide

If your project is in a different branch, switch to the main branch (usually 'main' or 'master').

Create a gh-pages Branch

How To Deploy a React App on GitHub Pages (Two Different Ways)
How To Deploy a React App on GitHub Pages (Two Different Ways)

GitHub Pages uses a specific branch to build and serve your site. Let's create one:

git checkout --branch gh-pages

Configure GitHub Pages

GitHub Profile Setup Guide for Engineering Students πŸš€
GitHub Profile Setup Guide for Engineering Students πŸš€

Now, let's tell GitHub to use this branch for GitHub Pages.

git remote add origin https://github.com/yourusername/your-repo.git

git branch -M main

How to Build a GitHub Portfolio That Gets Noticed
How to Build a GitHub Portfolio That Gets Noticed

git push -u origin main

Building and Deploying Your Site

How to Auto-Deploy Your Apps from GitHub in One Click?
How to Auto-Deploy Your Apps from GitHub in One Click?
Git & GitHub Explained for Beginners (2026)
Git & GitHub Explained for Beginners (2026)
Push Code to GitHub Explained πŸš€
Push Code to GitHub Explained πŸš€
Git and GitHub Commands PDF - Complete Guide for Beginners to ProπŸš€πŸ’»  #git #command #code
Git and GitHub Commands PDF - Complete Guide for Beginners to ProπŸš€πŸ’» #git #command #code
Deploy vite app to GitHub pages for Free
Deploy vite app to GitHub pages for Free
Introduction to Git & Version Control | Beginner's Guide
Introduction to Git & Version Control | Beginner's Guide
Simplify WordPress Deployment with GitHub Actions: Beginner's Guide
Simplify WordPress Deployment with GitHub Actions: Beginner's Guide
AI agent workflow github open source deploy
AI agent workflow github open source deploy
#8:GitHub Actions Tutorial |Introduction to GitHub Actions| Automatic Deployment With GitHub Actions
#8:GitHub Actions Tutorial |Introduction to GitHub Actions| Automatic Deployment With GitHub Actions
GitHub - peaceiris/actions-gh-pages: GitHub Actions for GitHub Pages πŸš€ Deploy static files and publish your site easily. Static-Site-Generators-friendly.
GitHub - peaceiris/actions-gh-pages: GitHub Actions for GitHub Pages πŸš€ Deploy static files and publish your site easily. Static-Site-Generators-friendly.
Flutter for the Webβ€Šβ€”β€ŠDeploy to Github
Flutter for the Webβ€Šβ€”β€ŠDeploy to Github
Git vs GitHub Explained (Day 24 Git Guide)
Git vs GitHub Explained (Day 24 Git Guide)
Setup your own GitLab with Docker
Setup your own GitLab with Docker
Deploying React Apps: A Guide to Using GitHub Pages
Deploying React Apps: A Guide to Using GitHub Pages
the github chat sheet is displayed in this screenshote screen graber
the github chat sheet is displayed in this screenshote screen graber
Automate Development: CI/CD with GitHub & Docker βš™οΈπŸš€
Automate Development: CI/CD with GitHub & Docker βš™οΈπŸš€
The Ultimate Guide to GitHub: Master Version Control πŸ“–πŸ› οΈ
The Ultimate Guide to GitHub: Master Version Control πŸ“–πŸ› οΈ
Easy web deployment with GitHub Copilot
Easy web deployment with GitHub Copilot
git push – Upload Local Commits to Remote Repository
git push – Upload Local Commits to Remote Repository
GitHub vs. Netlify
GitHub vs. Netlify

Next, we'll build and deploy your site. This process might vary depending on your project's tech stack.

For a simple HTML site, you can directly deploy it. For more complex projects, you might need to build it first. Here's how:

Building Your Site

If you're using a static site generator like Jekyll, Hugo, or Gatsby, build your site locally:

npm run build or yarn build (for Gatsby)

Deploying Your Site

Now, let's push your built site to the 'gh-pages' branch:

git add -A

git commit -m "Build and deploy site"

git push origin gh-pages

Accessing Your Live Site

GitHub Pages should now serve your site. It might take a few minutes to propagate.

You can access your live site at https://yourusername.github.io/your-repo/

Custom Domain (Optional)

If you want to use a custom domain, follow GitHub's guide to add a custom domain to your repository.

Once added, update your DNS settings with your domain registrar to point to GitHub's servers.

Congratulations! You've successfully deployed your site to GitHub Pages. Keep updating and improving your site, and don't forget to share it with the world!