Sub topic 1
What GitHub Pages is and what it serves
GitHub Pages is a static hosting service built into GitHub. It takes files from a repository and serves them over HTTPS at a github.io address or at your own domain. This chapter covers what it serves, what it cannot do, and how a request reaches your files.
Prerequisites
This chapter assumes you already have:
- Basic Git usage: clone, commit, push, and branches.
- A GitHub account and a repository.
- Basic HTML and CSS.
- Comfort reading YAML files, which later chapters use for workflows.
What "static" means
A static site is a set of files that the server sends to the browser exactly as they are stored. HTML, CSS, JavaScript, images, fonts, and PDFs all qualify. The server does no work per request except find the file and return it.
A dynamic site runs code on the server for each request. It might query a database, check a login, or build a page from a template. GitHub Pages does not do this.
| Works on GitHub Pages | Does not work on GitHub Pages |
|---|---|
| HTML, CSS, and images | PHP, Python, or Node.js running on the server |
| JavaScript that runs in the browser | Server-side databases |
| Sites generated ahead of time by a build tool | Server-side login and sessions |
| Calls from browser JavaScript to external APIs | Code that handles form posts on the host |
Browser JavaScript is allowed because it runs on the visitor's machine, not on GitHub's servers. A page can fetch data from a third-party API or a form service, but GitHub Pages itself only delivers the files.
How a request reaches your files
When a visitor opens your site, the browser asks GitHub's servers for a path. GitHub maps that path to a file in your published content. If the path points to a folder, it looks for index.html in that folder. If no file matches, the visitor sees a 404 page.
The published content is not always the same as the repository. You choose a publishing source, either a branch and folder or a GitHub Actions workflow. Later chapters cover both. Only the published content is served.
A minimal page
A single index.html at the publishing root is enough for a first deployment. The stylesheet link is relative, so it keeps working when the site is served from a project path.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>My site</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<h1>Hello from GitHub Pages</h1>
</body>
</html>Place a style.css file next to it. If that file is missing, the page still loads, but the browser reports a 404 for the stylesheet and shows the page unstyled. Missing assets are a common cause of broken-looking sites, and the troubleshooting chapter returns to them.
What GitHub Pages gives you
- A free
github.ioaddress, with HTTPS available. - Publishing tied to Git, so a push can update the live site.
- Support for custom domains.
- Optional Jekyll processing, which turns Markdown and templates into HTML. You can turn it off.
What GitHub Pages does not give you
- No server-side code, as described above.
- No private hosting by default. Published sites are generally publicly reachable, even when the source repository is private, though some plans allow access control. Check the current GitHub documentation for your plan.
- No unlimited use. GitHub documents usage limits and acceptable use rules, which a later chapter covers.
Check your understanding
Exercise
A teammate wants to host a site on GitHub Pages where a Python script on the server checks a visitor's password before showing a page. Can GitHub Pages do this? What could they do instead?
Show answer
No. GitHub Pages serves static files and cannot run server-side code such as a Python script. Password checks done in browser JavaScript would expose the logic and any secrets to every visitor, so they are not secure. The teammate should use a host that runs server-side code for the protected part, or use an external authentication service. They can still use GitHub Pages for the public static pages.
Exercise
A visitor requests a folder path on your site, such as /docs/, and the folder has no index.html. What do they see, and why?
Show answer
They see a 404 page. GitHub Pages maps a folder path to an index.html file in that folder. With no index.html and no other matching file, nothing matches the request.