codingstuff.io
ExploreTutorialsProblemsCS Subjects
Get Started
ExploreTutorialsProblemsCS Subjects
Get Started
codingstuff.io

Master the art of building software through interactive tutorials, real-world problems, and guided projects.

Pune, Maharashtra, India

codingstuffmail@gmail.com

Product

  • Explore
  • Tutorials
  • Problems
  • CS Subjects

Company

  • About
  • Contact
  • Privacy Policy
  • Terms & Conditions
  • Sitemap

© 2026 codingstuff.io. All rights reserved.

Built with ❤️ for developers everywhere

/
/
All Tutorials
📦

Git & GitHub

28 / 63 topics
20Introduction to GitHub21Creating and Managing GitHub Accounts22Creating and Managing Repositories on GitHub23Forking Repositories24Using Pull Requests25Managing Issues on GitHub26Using Milestones and Labels27Creating and Managing Wikis28Publishing with GitHub Pages
Tutorials/Git & GitHub/Publishing with GitHub Pages
📦Git & GitHub

Publishing with GitHub Pages

Updated 2026-04-20
4 min read

Publishing with GitHub Pages

GitHub Pages is a powerful feature that allows you to host static websites directly from your GitHub repositories for free. This tutorial will walk you through the process of setting up and publishing a website using GitHub Pages, including creating a repository, configuring settings, and customizing your site.

Prerequisites

Before you start, ensure you have the following:

  • A GitHub account.
  • Basic knowledge of Git and version control systems.
  • A static website or some HTML/CSS/JavaScript files to host.

Step 1: Create a Repository

  1. Log in to GitHub: Go to GitHub and log in with your credentials.

  2. Create a New Repository:

    • Click on the "+" icon in the upper-right corner and select "New repository".
    • Name your repository something like username.github.io (replace username with your GitHub username). This is crucial for GitHub Pages to recognize it as a user site.
    • Choose whether the repository should be public or private. User sites must be public.
    • Initialize the repository with a README file if you prefer.
  3. Clone the Repository:

    • Copy the HTTPS URL of your repository from the "Quick setup" section.
    • Clone the repository to your local machine using Git:
      git clone https://github.com/username/username.github.io.git
      cd username.github.io
      

Step 2: Add Your Website Files

  1. Add HTML/CSS/JavaScript Files:

    • Place your website files (HTML, CSS, JavaScript) in the root directory of the cloned repository.
    • Ensure you have an index.html file as the homepage.
  2. Commit and Push Changes:

    • Add your files to the staging area:
      git add .
      
    • Commit your changes with a descriptive message:
      git commit -m "Initial commit of website"
      
    • Push your changes to GitHub:
      git push origin main
      

Step 3: Configure GitHub Pages

  1. Access Repository Settings:

    • Go to your repository on GitHub.
    • Click on the "Settings" tab.
  2. Enable GitHub Pages:

    • Scroll down to the "Pages" section.
    • Under "Source", select the branch you want to publish (usually main or master) and the folder (/root).
    • Click "Save".
  3. Wait for Deployment:

    • GitHub will automatically build and deploy your site. This process can take a few minutes.
    • Once complete, you'll see a URL where your site is hosted (e.g., https://username.github.io).

Step 4: Customize Your Site

  1. Add a Custom Domain:

    • If you have a custom domain, go to the "Pages" settings in your repository.
    • Click on "Custom domain" and enter your domain name.
    • Save changes and follow the instructions provided by GitHub to update your DNS records.
  2. Use Jekyll for Static Site Generation:

    • GitHub Pages supports Jekyll, a static site generator written in Ruby.
    • To use Jekyll, create a _config.yml file in the root of your repository with basic configuration settings.
    • Example _config.yml:
      title: My Website
      description: A simple website hosted on GitHub Pages
      theme: minima
      
  3. Add Themes and Plugins:

    • Jekyll has a wide range of themes and plugins available.
    • To use a theme, add it to your _config.yml file:
      remote_theme: jekyll/minimal
      
    • For plugins, ensure they are compatible with GitHub Pages and listed in the GitHub Pages Dependency Versions.

Step 5: Maintain Your Site

  1. Update Your Website:

    • Make changes to your website files locally.
    • Commit and push the changes to GitHub:
      git add .
      git commit -m "Update website content"
      git push origin main
      
  2. Monitor and Troubleshoot:

    • Check the "Actions" tab in your repository for build logs if you encounter issues.
    • Use GitHub's built-in features to manage comments, issues, and pull requests.

Best Practices

  • Keep Your Repository Clean: Avoid committing unnecessary files like node_modules or large binary files.
  • Use Version Control: Regularly commit and push changes to keep track of your website's evolution.
  • Backup Your Files: Although GitHub Pages is reliable, it's good practice to maintain backups of your website files.
  • Test Locally: Before pushing changes, test your site locally to ensure everything works as expected.

Conclusion

GitHub Pages provides a simple and effective way to host static websites. By following this tutorial, you should be able to set up, customize, and maintain your own GitHub-hosted website. Whether you're building a personal portfolio or a documentation site, GitHub Pages offers the tools and flexibility to meet your needs.


PreviousCreating and Managing WikisNext Introduction to GitHub Actions

Recommended Gear

Creating and Managing WikisIntroduction to GitHub Actions