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…
Section overview
5 resourcesCovers 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
-
Exercise: Create a simple 'Hello, World!' webpage and deploy it using GitHub Pages.
Solution: Follow the steps in the tutorial, using a singleindex.htmlfile containing<h1>Hello, World!</h1>. -
Exercise: Add a CSS file to your GitHub Pages site and use it to style your 'Hello, World!' page.
Solution: Create astyles.cssfile in your repository, link it in yourindex.html, and add some styles. Don't forget to commit and push the changes! -
Exercise: Add a second page to your site, linked from your 'Hello, World!' page.
Solution: Create asecond.htmlfile, and add a link to it inindex.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.
Related topics
Keep learning with adjacent tracks.
Popular tools
Helpful utilities for quick tasks.
Latest articles
Fresh insights from the CodiWiki team.
AI in Drug Discovery: Accelerating Medical Breakthroughs
In the rapidly evolving landscape of healthcare and pharmaceuticals, Artificial Intelligence (AI) in drug dis…
Read articleAI in Retail: Personalized Shopping and Inventory Management
In the rapidly evolving retail landscape, the integration of Artificial Intelligence (AI) is revolutionizing …
Read articleAI 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 articleAI 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 articleAI in Legal Compliance: Ensuring Regulatory Adherence
In an era where technology continually reshapes the boundaries of industries, Artificial Intelligence (AI) in…
Read article