Deploying with GitHub Pages

1

Deploying with GitHub Pages

▶

Once you have built a webpage — even a simple one made of HTML, CSS, and JavaScript — you need somewhere to host it so that other people can view it on the internet. Traditionally, hosting meant renting server space, configuring a web server, and uploading files through FTP or a similar tool. GitHub Pages removes all of that complexity. It is a free static-site hosting service built directly into GitHub, and it lets you turn any repository into a live, publicly accessible website with just a few clicks. For student projects, portfolios, and coursework, it is one of the most practical and widely used deployment options available today.

What is GitHub Pages?

GitHub Pages works by reading the files in a designated branch of your GitHub repository and serving them as a website. When someone visits your site's URL, GitHub's servers deliver your index.html, CSS stylesheets, JavaScript files, and any other assets directly to that visitor's browser — exactly the same way a traditional web server would. The key difference is that you do not have to set up or manage the server yourself. GitHub handles all of that infrastructure behind the scenes.

  • Free hosting for every GitHub user. Every GitHub account — personal or organizational — gets at least one free GitHub Pages site. There are no monthly fees, no billing details to enter, and no bandwidth limits that typically affect small student projects. This makes it genuinely accessible for anyone learning web development.
  • Static files only. GitHub Pages serves static content, meaning HTML, CSS, JavaScript, images, fonts, and other files that the browser can display or execute directly. It does not run server-side languages like Python, PHP, or Node.js on your behalf. For the purposes of this course — building and showcasing front-end web projects — this is not a limitation at all.
  • Publicly accessible by default. The moment you enable GitHub Pages, your site is visible to anyone in the world who has the URL. This is a feature, not a bug: it means you can share your live project with instructors, classmates, future employers, or anyone else without requiring them to have a GitHub account or install anything.

Enabling GitHub Pages on Your Repository

Before GitHub Pages can publish your site, you need to tell GitHub which branch and folder to use as the source of your web files. The following steps walk you through that process from start to finish.

  • Open your repository's Settings. Navigate to your repository on GitHub (for example, https://github.com/your-username/your-repo-name). Near the top of the repository page you will see a row of tabs: Code, Issues, Pull requests, Actions, Projects, Security, Insights, and Settings. Click Settings. If you do not see this tab, make sure you are logged in as the owner of the repository, because only the owner or collaborators with admin access can change these settings.
  • Find the Pages section. In the Settings page, look at the left-hand sidebar. Scroll down until you find the section labeled Pages — it is listed under the "Code and automation" group. Click it. This brings up the GitHub Pages configuration panel for your repository.
  • Choose your source branch and folder. Under the heading "Build and deployment," you will see a "Source" dropdown (which should say "Deploy from a branch") and a "Branch" dropdown below it. Click the Branch dropdown and select main (or whatever your repository's default branch is named — some older repositories use master). Next to the branch dropdown is a folder dropdown; set it to / (root). This tells GitHub Pages to look for your web files directly in the root of that branch rather than in a subdirectory. Finally, click Save.

After you click Save, GitHub immediately begins its first build-and-deploy cycle. This usually takes between 30 seconds and a couple of minutes for a simple project.

Understanding the Automatic Publishing Process

One of the most valuable aspects of GitHub Pages is that deployment is continuous and automatic. You do not need to run a separate deploy command, upload files through a control panel, or press a "publish" button each time you make a change. The workflow is simple and powerful:

  • Edit → commit → push → live. Whenever you push one or more commits to your source branch (the branch you selected in the Pages settings), GitHub detects the new commits and automatically triggers a fresh build and deployment of your site. Within a minute or two, your changes are live at your public URL. This tight feedback loop is excellent for learning, because you can make a small change, push it, and immediately see the result in a real browser on the real web.
  • No manual upload or separate tool required. Unlike older workflows where you might use an FTP client to copy files to a remote server, GitHub Pages treats your repository itself as the source of truth. Whatever is on your chosen branch is your website. Keeping your code in version control and deploying it are no longer two separate steps — they happen together automatically.
  • Monitoring your deployment status. GitHub gives you two convenient ways to check whether your latest deployment succeeded. First, you can return to Settings → Pages and look for a banner or link at the top that says something like "Your site is live at https://…" — this confirms that the most recent deployment completed successfully. Second, you can click the Actions tab in your repository and look for a workflow run labeled "pages build and deployment." A green checkmark means success; a red X means something went wrong and you can click the run to read the error log.

Your Live Public URL

Once GitHub Pages is enabled and your first deployment completes, your site is assigned a permanent public URL. Understanding the structure of this URL is important, because it affects how you write links and reference assets inside your project.

  • Standard URL format. The URL follows a predictable pattern: https://[your-username].github.io/[repository-name]/. For example, if your GitHub username is jsmith and your repository is named portfolio, your site's URL will be https://jsmith.github.io/portfolio/. The username portion is your actual GitHub login name, and the repository-name portion is exactly as it appears in your repository's URL — including any hyphens, underscores, or capitalization (though all-lowercase repository names are conventional and avoid potential case-sensitivity issues).
  • Where to find your URL. GitHub displays your site's URL prominently in the Pages settings panel once deployment succeeds. You will see a box at the top of the Pages settings that reads "Your site is live at" followed by the clickable link. You can copy this URL directly from that panel.
  • Sharing your URL. Because the URL is public and requires no login to access, you can paste it into an email, a course submission form, a chat message, or a portfolio document, and anyone who clicks it will see your live website immediately in their browser. This is one of the greatest practical advantages of GitHub Pages for coursework: submitting a live, clickable link rather than attaching a zip file of HTML files.

Verifying Your Deployment

After enabling Pages and waiting for the initial deployment to finish, it is important to verify that everything is working correctly before you share the URL with anyone.

  • Open the URL in a new browser tab. Copy the URL from the Pages settings panel and paste it into a new browser tab (or an entirely different browser, or even your phone's browser, to get a clean view with no cached files). If everything is configured correctly, you will see your webpage load just as it does when you open the HTML file locally.
  • The role of index.html. When a visitor navigates to the root of your site — for example, https://jsmith.github.io/portfolio/ — the web server needs to know which file to serve. By convention, web servers (including GitHub Pages) automatically look for a file named exactly index.html in the requested folder and serve it as the default page. This is why your main HTML file must be named index.html (all lowercase, spelled exactly), placed in the root of your repository. If the file is named Index.html, home.html, or index.HTML, GitHub Pages will not automatically find it and your homepage will not load.
  • Troubleshooting a 404 error. If you see a "404 — There isn't a GitHub Pages site here" error, work through this checklist systematically:
    • Return to Settings → Pages and confirm that Pages is actually enabled — the branch dropdown should show your chosen branch (e.g., main) and the folder should show / (root).
    • Check that you clicked Save after making those selections — if you navigated away without saving, the settings were not applied.
    • Verify in the Code tab of your repository that a file named exactly index.html exists in the root folder (not inside a subfolder).
    • Check the Actions tab to confirm the deployment workflow completed successfully. If there is a red X, read the error log for clues.
    • Wait a minute or two and try again — very occasionally the first deployment takes longer than expected, especially right after a new repository is created.

With your GitHub Pages site verified and live, you have completed a genuinely professional workflow: writing code, managing it with version control, and deploying it to a real public web server — all through a single integrated platform. This is a foundational skill that carries directly into real-world web development practice.

NotesEmphasise to students that the repository must be public (on a free GitHub account) for GitHub Pages to work. If a student sees no Pages option or the published site returns a 404, the most common causes are: the repository is private, the file is not named exactly `index.html`, or the Save button was not clicked after selecting the branch. Encourage students to check the Actions tab for deployment status rather than only refreshing the live URL.