Sub topic 2
User, organization, and project sites and their URLs
This chapter assumes you can clone, commit, and push with Git, you have a GitHub account, and you can read basic HTML. Here you learn the three kinds of GitHub Pages sites and how to predict the URL each one gets.
Three kinds of sites
GitHub Pages serves static files from a repository. The kind of site depends on the repository name and on who owns the repository.
- A user site belongs to a personal account. Its repository is named
USERNAME.github.io. - An organization site belongs to an organization. Its repository is named
ORGNAME.github.io. - A project site belongs to any other repository, under a personal account or an organization.
An account can have one user or organization site. It can have many project sites, one per repository.
How the URL is built
The URL follows from the repository name. A user or organization site is served from the root of the github.io hostname. A project site is served from a path that matches the repository name.
| Site type | Repository | URL |
|---|---|---|
| User | `octocat/octocat.github.io` | `https://octocat.github.io/` |
| Organization | `acme/acme.github.io` | `https://acme.github.io/` |
| Project | `octocat/recipes` | `https://octocat.github.io/recipes/` |
| Project | `acme/docs` | `https://acme.github.io/docs/` |
The project path is the main difference between the types. It affects how you write links, which a later chapter covers.
Matching the name exactly
The special repository name must match the account name. Take the account octocat. The repository octocat.github.io becomes a user site. A repository named octocat-site.github.io does not, and GitHub treats it as a project site. It would be served at https://octocat.github.io/octocat-site.github.io/.
Hostnames are lowercase. If your username has capital letters, the URL still uses lowercase letters.
Which type to choose
- Use a user site for a personal home page or portfolio.
- Use an organization site for a landing page that represents the whole organization.
- Use a project site to document or demo a single repository. This is the usual choice, because one account can have many.
You can mix them. A user site at octocat.github.io can link to project sites under octocat.github.io/recipes/. They share one hostname, so they appear to be parts of one website.
Seeing the type in practice
You can find the URL for any repository in its settings. Open Settings, then Pages. After the first successful deployment, the page shows the live address. For a repository named recipes owned by octocat, expect the address https://octocat.github.io/recipes/.
The same index.html behaves differently depending on the type. Here is a page with a stylesheet link:
<!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>The link style.css has no leading slash, so it is relative to the page. It resolves to /style.css on a user site and to /recipes/style.css on the project site. A link written as /style.css would point to the hostname root in both cases. On a project site that is the wrong place, and the stylesheet would return a 404 error.
Custom domains change the URL
A custom domain replaces the github.io address. With a custom domain, a project site is no longer under a repository path. If the account's user site has a custom domain such as example.com, project sites of that account are served beneath it, for example https://example.com/recipes/. A later chapter covers domain setup in full.
Common mistakes
- Misspelling the account name in the repository name, so the site is treated as a project site.
- Expecting a project site at the hostname root.
- Creating a second user site. An account has only one, so use project sites for additional content.
- Using root-relative asset links on a project site.
Exercise
The account acme has a repository named docs and a repository named acme.github.io. What URLs do the two sites get, and which one is the project site?
Show answer
The repository acme.github.io is the organization site at https://acme.github.io/. The repository docs is the project site at https://acme.github.io/docs/.
Exercise
A project site at https://octocat.github.io/recipes/ loads without styles. The page uses <link rel="stylesheet" href="/style.css">. What is the cause and the fix?
Show answer
The leading slash points to the hostname root, https://octocat.github.io/style.css, which does not exist. Change the link to style.css (relative) or to /recipes/style.css.