AlgoMaster Logo

GitHub Pages

Last Updated: January 3, 2026

6 min read

GitHub Pages provides a straightforward way to host websites directly from your GitHub repositories. Whether you want to showcase your portfolio, create documentation, or run a blog, GitHub Pages can get you up and running with minimal effort.

This chapter will guide you through every aspect of GitHub Pages, from setting it up to customizing it for your specific needs.

Understanding GitHub Pages

GitHub Pages is a static site hosting service that is built into GitHub. It allows you to serve HTML, CSS, and JavaScript files directly from your repositories. This service is especially useful for:

  • Project Documentation: Create comprehensive and user-friendly documentation for your projects.
  • Personal Portfolios: Showcase your work and skills with a professional portfolio.
  • Blogs: Share your thoughts and insights on topics you care about.
  • Landing Pages: Promote specific projects or initiatives with a dedicated landing page.

GitHub Pages works by using the contents of a specific branch in your repository, typically the main branch or a dedicated branch called gh-pages. When you push changes to these branches, your website updates automatically.

Setting Up Your First GitHub Page

Setting up a GitHub Page is straightforward. Here’s how to get started:

Step 1: Create a Repository

  1. Navigate to GitHub and create a new repository.
  2. Name your repository using the format username.github.io. For example, if your GitHub username is johndoe, name your repository johndoe.github.io.
  3. Optionally, add a README file and choose a license.

Step 2: Enable GitHub Pages

  1. Go to the repository's settings.
  2. Scroll down to the "GitHub Pages" section.
  3. Under "Source," select the branch you want to use for your GitHub Pages site. Choose main or create a new branch called gh-pages.
  4. Click "Save". After a few moments, GitHub will provide you with a URL where your site is hosted.

Example Repository Structure

Your repository should look something like this:

The index.html file is the entry point for your website.

Creating Your First Page

Now that you’ve set up your GitHub Pages site, let’s create a simple HTML page.

Step 1: Create an index.html File

Create a file named index.html in the root of your repository. Here’s a simple example:

Step 2: Add Styles

Create a styles directory and a main.css file for styling. Here’s a basic example:

Step 3: Commit Your Changes

Using the command line or GitHub interface, commit the changes:

After a moment, navigate to to see your new page live.

Customizing Your GitHub Page

Once your basic site is up and running, you can customize it in various ways.

Custom Domains

If you have a custom domain, you can configure it with GitHub Pages. Here’s how:

  1. Add a CNAME file to the root of your repository with your custom domain name inside it.
  2. Configure your DNS settings to point to GitHub's servers. You’ll typically need to add A records pointing to 185.199.108.153, 185.199.109.153, 185.199.110.153, and 185.199.111.153.
  3. After a few minutes, your custom domain should work with your GitHub Pages site.

Example CNAME File

Your CNAME file might look like this:

Using Jekyll for Static Site Generation

GitHub Pages supports Jekyll, a static site generator. Jekyll allows you to use templates, layouts, and Markdown to create a more dynamic site.

Step 1: Create a _config.yml File

In the root of your repository, create a _config.yml file to configure your Jekyll site:

Step 2: Create Markdown Files

Instead of creating HTML files directly, you can create Markdown files. For instance, create a file named about.md:

Step 3: Commit and Push Your Changes

Your site will now render the Markdown file using the specified layout.

Advanced Features of GitHub Pages

GitHub Pages has several advanced features that can enhance your site.

Using GitHub Actions for Automation

You can use GitHub Actions to automate tasks like deploying your site. For example, you can set up a workflow to build and deploy your Jekyll site automatically when you push changes.

Example Workflow File

Create a .github/workflows/deploy.yml file with the following content:

This workflow will build your Jekyll site and deploy it to GitHub Pages whenever you push changes to the main branch.

Managing Multiple Environments

GitHub Pages can also manage multiple environments using different branches. For instance, you might have a develop branch for testing and a main branch for production.

  • Develop Branch: Use for development and testing features.
  • Main Branch: Use for stable releases.

You can configure GitHub Pages to serve from either branch by changing the settings in the repository.

Troubleshooting Common Issues

Sometimes things don’t go as planned. Here are some common issues and how to resolve them:

404 Errors

If you encounter a 404 error, it might be because:

  • Your repository name is incorrect (it should follow the username.github.io format).
  • The branch selected in GitHub Pages settings is not correct.

Cache Issues

Web browsers can cache old versions of your site. If you make changes and they don’t appear, try clearing your browser cache or using a private/incognito window.

Missing Assets

Make sure all asset paths (like images or CSS) are correct. Use relative paths to ensure they work regardless of the page.

Now that you understand how to create and customize GitHub Pages, you are ready to explore GitHub Releases.

In the next chapter, we will look at how to effectively manage versioning and distribute your software with GitHub Releases, ensuring your projects are easily accessible to users.