Last Updated: January 3, 2026
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.
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:
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 a GitHub Page is straightforward. Here’s how to get started:
username.github.io. For example, if your GitHub username is johndoe, name your repository johndoe.github.io.main or create a new branch called gh-pages.Your repository should look something like this:
The index.html file is the entry point for your website.
Now that you’ve set up your GitHub Pages site, let’s create a simple HTML page.
index.html FileCreate a file named index.html in the root of your repository. Here’s a simple example:
Create a styles directory and a main.css file for styling. Here’s a basic example:
Using the command line or GitHub interface, commit the changes:
After a moment, navigate to to see your new page live.
Once your basic site is up and running, you can customize it in various ways.
If you have a custom domain, you can configure it with GitHub Pages. Here’s how:
CNAME file to the root of your repository with your custom domain name inside it.A records pointing to 185.199.108.153, 185.199.109.153, 185.199.110.153, and 185.199.111.153.Your CNAME file might look like this:
GitHub Pages supports Jekyll, a static site generator. Jekyll allows you to use templates, layouts, and Markdown to create a more dynamic site.
_config.yml FileIn the root of your repository, create a _config.yml file to configure your Jekyll site:
Instead of creating HTML files directly, you can create Markdown files. For instance, create a file named about.md:
Your site will now render the Markdown file using the specified layout.
GitHub Pages has several advanced features that can enhance your site.
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.
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.
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.
You can configure GitHub Pages to serve from either branch by changing the settings in the repository.
Sometimes things don’t go as planned. Here are some common issues and how to resolve them:
If you encounter a 404 error, it might be because:
username.github.io format).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.
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.