Git & GitHub / GitHub Pages and Hosting

Deploying Websites with GitHub Pages

In this tutorial, you will learn how to deploy your static website with GitHub Pages. We will guide you through the process of setting up a GitHub repository for your site, pushin…

Tutorial 1 of 5 5 resources in this section

Section overview

5 resources

Covers deploying static websites using GitHub Pages.

1. Introduction

In this tutorial, we will learn how to deploy a static website using GitHub Pages. This platform allows us to transform our repositories into websites to showcase our projects, documentation, or portfolio.

By the end of this tutorial, you will be able to:

  • Initialize a new GitHub repository
  • Add your HTML files to this repository
  • Deploy your site using GitHub Pages

Prerequisites: Basic knowledge of HTML and Git.

2. Step-by-Step Guide

2.1 Creating a new GitHub repository

Start by signing in to your GitHub account. Click on the '+' icon at the top right corner of the homepage and select 'New repository'. Provide a name for the repository, for example, 'my-website'. Leave it as a public repository and initialize it with a README.

2.2 Pushing your HTML files

Clone the repository to your local machine using the command:

git clone https://github.com/username/my-website.git

Replace 'username' with your GitHub username.

Navigate into the cloned repository and add your HTML files:

cd my-website
// Add your HTML files here

Then, push them to the GitHub repository:

git add .
git commit -m "Initial commit"
git push origin master

2.3 Configuring your site's settings for deployment

Go back to your GitHub repository and navigate to 'Settings'. Scroll down to the 'GitHub Pages' section. Under 'Source', select 'master branch'. Your site is now published at 'https://username.github.io/my-website'.

3. Code Examples

3.1 Creating and Cloning a Repository

# Create a new repository on GitHub
# Clone the repository to your local machine
git clone https://github.com/username/my-website.git

3.2 Adding HTML files and pushing to GitHub

# Navigate into the cloned repository
cd my-website

# Add your HTML files here
# ...

# Add the files to the staging area
git add .

# Commit the changes
git commit -m "Initial commit"

# Push to the master branch
git push origin master

4. Summary

In this tutorial, you've learned how to:

  • Create a new GitHub repository
  • Clone this repository to your local machine
  • Add HTML files to this repository
  • Deploy your site using GitHub Pages

Next steps: Learn how to customize your GitHub Pages site with Jekyll, add a custom domain, or set up a CI/CD pipeline.

Additional resources: GitHub Pages Documentation, Jekyll Documentation

5. Practice Exercises

  1. Exercise: Create a simple 'Hello, World!' webpage and deploy it using GitHub Pages.
    Solution: Follow the steps in the tutorial, using a single index.html file containing <h1>Hello, World!</h1>.

  2. Exercise: Add a CSS file to your GitHub Pages site and use it to style your 'Hello, World!' page.
    Solution: Create a styles.css file in your repository, link it in your index.html, and add some styles. Don't forget to commit and push the changes!

  3. Exercise: Add a second page to your site, linked from your 'Hello, World!' page.
    Solution: Create a second.html file, and add a link to it in index.html. Commit and push the changes, then verify that the link works on your published site.

Need Help Implementing This?

We build custom systems, plugins, and scalable infrastructure.

Discuss Your Project

Related topics

Keep learning with adjacent tracks.

View category

HTML

Learn the fundamental building blocks of the web using HTML.

Explore

CSS

Master CSS to style and format web pages effectively.

Explore

JavaScript

Learn JavaScript to add interactivity and dynamic behavior to web pages.

Explore

Python

Explore Python for web development, data analysis, and automation.

Explore

SQL

Learn SQL to manage and query relational databases.

Explore

PHP

Master PHP to build dynamic and secure web applications.

Explore

Popular tools

Helpful utilities for quick tasks.

Browse tools

Watermark Generator

Add watermarks to images easily.

Use tool

Random Number Generator

Generate random numbers between specified ranges.

Use tool

XML Sitemap Generator

Generate XML sitemaps for search engines.

Use tool

Word to PDF Converter

Easily convert Word documents to PDFs.

Use tool

WHOIS Lookup Tool

Get domain and IP details with WHOIS lookup.

Use tool

Latest articles

Fresh insights from the CodiWiki team.

Visit blog

AI in Drug Discovery: Accelerating Medical Breakthroughs

In the rapidly evolving landscape of healthcare and pharmaceuticals, Artificial Intelligence (AI) in drug dis…

Read article

AI in Retail: Personalized Shopping and Inventory Management

In the rapidly evolving retail landscape, the integration of Artificial Intelligence (AI) is revolutionizing …

Read article

AI in Public Safety: Predictive Policing and Crime Prevention

In the realm of public safety, the integration of Artificial Intelligence (AI) stands as a beacon of innovati…

Read article

AI in Mental Health: Assisting with Therapy and Diagnostics

In the realm of mental health, the integration of Artificial Intelligence (AI) stands as a beacon of hope and…

Read article

AI in Legal Compliance: Ensuring Regulatory Adherence

In an era where technology continually reshapes the boundaries of industries, Artificial Intelligence (AI) in…

Read article

Need help implementing this?

Get senior engineering support to ship it cleanly and on time.

Get Implementation Help