Step by Step Guide to Publishing a Website through GitHub Pages

Step by Step Guide to Publishing a Website through GitHub Pages

Learn how to publish your website effortlessly using GitHub Pages.

Get Started

Publishing with GitHub Pages

By Ryan Kopf, University of Iowa Computer Science
Last Updated May 21, 2024

GitHub Pages is a free service by GitHub that allows you to host static websites directly from a GitHub repository. This guide will walk you through the steps to publish your website using GitHub Pages.

Acceptable Uses

GitHub Pages is ideal for hosting project documentation, personal websites, portfolios, blogs, and other static content. It supports HTML, CSS, JavaScript, and Jekyll, making it a versatile platform for developers and designers to showcase their work or share information.

Unacceptable Uses

GitHub Pages should not be used for commercial purposes that involve selling products or services, hosting server-side code, running databases, or any other dynamic content that requires backend processing. Additionally, it is not suitable for hosting malware, phishing sites, or any content that violates GitHub's terms of service. Their Terms of Service specifically states "GitHub Pages is not intended for or allowed to be used as a free web-hosting service to run your online business".

Step 1: Create a GitHub Repository

First, you need to create a GitHub account if you don't already have one. Once logged in, create a new repository. You can name it anything, but for user or organization pages, it should be named username.github.io.

What is GitHub?

GitHub is a web-based platform for version control and collaboration, allowing multiple people to work on a project simultaneously. It uses Git, a powerful version control system, to track changes in source code during software development. GitHub provides a range of features including issue tracking, project management, and continuous integration to streamline development workflows. With GitHub, you can host your code repositories, collaborate with others, and deploy static websites using GitHub Pages.

Step 2: Add Your Website Files

Add your HTML, CSS, and JavaScript files to the repository. You can do this by uploading files directly on the GitHub website or by using Git commands if you have Git installed on your computer.

Sample Commands to Add Your Website Files

Follow these steps to create and add your website files:

  1. Create a new file: Open Notepad (or any text editor) and create a new file named index.html. This will be the default home page of your website.
  2. Write HTML code: Add the following basic HTML template to your index.html file:
    <!DOCTYPE html>
    <html lang="en">
    <head>
      <meta charset="UTF-8">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <title>My GitHub Pages Website</title>
    </head>
    <body>
      <h1>Hello, GitHub Pages!</h1>
      <p>This is a sample website hosted with GitHub Pages.</p>
    </body>
    </html>
  3. Save the file: Save the file as index.html.
  4. Open Git Bash: Open Git Bash (or your preferred Git client) and navigate to the directory containing your index.html file.
  5. Initialize a new Git repository: Initialize a new Git repository using the following command:
    git init
  6. Add the file to the repository: Add the index.html file to the repository using the following command:
    git add index.html
  7. Commit the file: Commit the file with a message using the following command:
    git commit -m "Initial commit"
  8. Connect to your GitHub repository: Add the remote URL for your GitHub repository using the following command (replace USERNAME and REPO with your GitHub username and repository name):
    git remote add origin https://github.com/USERNAME/REPO.git
  9. Push the files to GitHub: Push the files to your GitHub repository using the following command:
    git push -u origin main

Your index.html file is now added to your GitHub repository and will be available at https://USERNAME.github.io/REPO.

Step 3: Enable GitHub Pages

In your repository, go to the "Settings" tab. Scroll down to the "GitHub Pages" section. In the "Source" dropdown, select the branch you want to use for GitHub Pages (usually "main" or "master"). Click "Save" to enable GitHub Pages.

Step 4: Access Your Published Website

After enabling GitHub Pages, your website will be published at https://username.github.io (replace "username" with your GitHub username). It might take a few minutes for the site to go live.

Troubleshooting

If your site doesn't appear, ensure that your repository is public and that your files are in the correct branch. Check the GitHub Pages section in your repository settings for any error messages.

For more details on troubleshooting, you can refer to the GitHub Pages documentation.

Customizing Your Site

You can customize your GitHub Pages site using Jekyll, a static site generator. Jekyll allows you to use templates, includes, and other features to create a more dynamic site. For more information, see the GitHub Pages with Jekyll documentation.

Try WebRaven

You can publish a free website using WebRaven too.

Get Started