Back to Blog
Lesson 47 of the Git & GitHub: Git & GitHub from Zero course
GitSeptember 3, 20264 min read

GitHub Pages Deployment: Hosting Your Static Site for Beginners

Learn how to use GitHub Pages for deployment. We’ll show you how to host a static site directly from your repository with simple, actionable steps.

github pagesdeploymentstatic sitegitgithubhosting
Close-up of colorful programming code on a computer screen, showcasing digital technology.

Previously in this course, we covered Advanced Branching Patterns to manage complex development cycles. Now that your project is stable and versioned, it’s time to share it with the world.

In this lesson, we are moving from local development to public hosting. You will learn how to use GitHub Pages to turn your repository into a live website, making your project accessible to anyone with a browser.

What is GitHub Pages?

GitHub Pages is a static site hosting service that takes files directly from your repository, builds them (if necessary), and serves them as a website. It is designed specifically for hosting documentation, personal portfolios, or simple project websites.

Because it serves static files—HTML, CSS, and JavaScript—you don't need a backend server, a database, or complex infrastructure. If you've been following our Project Setup Strategy, you likely already have the necessary assets to deploy your first site.

Enabling GitHub Pages

To host your site, you need to point GitHub to the files it should serve. Follow these steps to enable the service:

  1. Navigate to your repository on GitHub.
  2. Click the Settings tab in the top navigation bar.
  3. On the left-hand sidebar, find the Pages section under "Code and automation."
  4. Under Build and deployment, ensure the source is set to "Deploy from a branch."
  5. Select the branch you want to serve (usually main or master) and the folder (usually / (root)).
  6. Click Save.

Once saved, GitHub will automatically trigger a build process. You can monitor the progress under the "Actions" tab in your repository. After a few minutes, a link to your live site will appear at the top of the Pages settings page.

Deploying a Static Site: A Worked Example

Let’s assume your project repository contains an index.html file in the root directory. To make this your landing page, ensure your file structure looks like this:

TEXT
/my-project
├── .git/
├── index.html
├── style.css
└── README.md
  1. Commit your files: Ensure your index.html and style.css are committed to your main branch.
  2. Push to GitHub: Use git push origin main to sync your local work with the remote repository.
  3. Configure Pages: Follow the steps in the previous section to set the main branch as the source.
  4. Verify: GitHub will generate a URL in the format https://<username>.github.io/<repository-name>/. Visit this link to see your site live.

If your project requires more advanced build steps, you might explore Mastering Static Site Generation (SSG) in Next.js, but for now, keeping it simple with plain HTML is the perfect way to master the basics of deployment.

Hands-on Exercise

To practice, create a new folder named website in your project, add a simple index.html file inside it, and push it to your repository. Configure GitHub Pages to serve your site from the root directory. Once the deployment succeeds, click the provided link to view your page.

Common Pitfalls

  • The 404 Error: If your site returns a 404, double-check that your entry file is named index.html (all lowercase) and that it is located in the root of the branch you selected.
  • Missing Assets: If your images or CSS files aren't loading, verify your file paths. Use relative paths (e.g., src="images/logo.png") rather than absolute paths (e.g., src="/images/logo.png") to ensure they resolve correctly once deployed.
  • Case Sensitivity: Unlike some local Windows environments, GitHub's servers are case-sensitive. If your file is Index.html but your link says index.html, it will fail. Always use lowercase for filenames.

FAQ

Can I use a custom domain? Yes. In the GitHub Pages settings, there is a "Custom domain" field. You can point your own domain name (like www.yourname.com) to your GitHub Pages site by updating your DNS records.

Is there a cost for GitHub Pages? No, it is free for public repositories.

Can I host a backend (like Node.js or Python) on GitHub Pages? No. GitHub Pages is strictly for static content. If your project grows to require a server, you'll need to look into services like those discussed in Deploying a Static Frontend: Hosting and CDN Integration.

Recap

In this lesson, we enabled GitHub Pages and deployed a static site directly from a repository. You now know how to configure a build source and verify your live URL. This is a fundamental skill for showing off your work or publishing documentation, and it serves as the foundation for the more advanced Production Deployment: Automating Secure CD Pipelines techniques we will cover later in the course.

Up next: Analyzing Repository Health — we'll look at how to track visitor traffic and contributor activity to understand the impact of your project.

Similar Posts