blog github-pages

This article is about creating a website by GitHub Pages with Jekyll.
Jekyll is a static site generator. GitHub Pages uses Jekyll by default to create and publish sites.

Environment

  • Windows 10 64-bit
  • Git for Windows 2.44.0
  • Ruby 3.2.3
  • Jekyll 4.3.3

Prerequisites

  • Git is installed.
  • You have a GitHub account.

Steps to Create the Site

  1. Install Jekyll
  2. Create a site on GitHub Pages
  3. Clone the GitHub repository
  4. Create the site using Jekyll
  5. Check the site locally
  6. Commit and push the changes
  7. Change the repository settings
  8. View the site

Based on the following page:
Creating a GitHub Pages Site with Jekyll

1. Install Jekyll

For details on installing Jekyll, see here.

2. Create a site on GitHub Pages

For details on creating a GitHub Pages site, see here.

3. Clone the GitHub repository

You will use Jekyll to create the site.

  1. Go to GitHub.
    If you are not signed in, sign in.
  2. Access the page of the repository you created.
    Link to access the GitHub repository page
  3. Click “Code.”
  4. Copy the URL for cloning.
    Clone URL
  5. Clone the GitHub repository.
    Open Command Prompt or PowerShell and run the following:
    Replace <directory path where to clone the repository> with your desired path, and
    https://github.com/<username>/<repository>.git with the clone URL you copied.
    > cd <directory path where to clone the repository>
    > git clone https://github.com/<username>/<repository>.git
    

4. Create the site using Jekyll

  1. Navigate to the repository directory.
    Open Command Prompt or PowerShell and run:
    > cd <path to the repository directory>
    

    <path to the repository directory> is <directory where you cloned>/<repository name>.

  2. Delete the README.md file.
    If there is a README.md file in the root of the repository, delete it:
    > git rm README.md
    
  3. Create and move into the docs directory.
    Create the directory where you’ll generate the site and navigate into it:
    > mkdir docs
    > cd docs
    
  4. Create the site with Jekyll.
    Generate a Jekyll site in the current directory (docs):
    > jekyll new --skip-bundle .
    
  5. Modify the Gemfile.
    Open the generated Gemfile in a text editor and make the following changes:
    Since GitHub Pages uses the github-pages gem, uncomment the following line:
    gem "github-pages", group: :jekyll_plugins
    

    Add a version constraint like this:

    gem "github-pages", "~> <github-pages version>", group: :jekyll_plugins
    

    Replace <github-pages version> with the version listed under Dependency versions.

Comment out the line that defines jekyll, as it is already included in github-pages:

#gem "jekyll", "~> <jekyll version>"
  1. Modify _config.yml.
    Open _config.yml in a text editor and update the following fields.
    Comment out any fields you do not want to display on your site.
Field Description
title Enter your site’s title.
description Enter a description for your site.
twitter_username Enter your X (formerly Twitter) username.
github_username Enter your GitHub username.
  1. Install the gems.
    To install the necessary gems, run:
    > bundle install
    

5. Check the Site Locally

  1. Start a local server.
    Open Command Prompt or PowerShell and run the following:
    > cd <path to the repository>/docs
    > bundle add webrick # Run this if you are using Ruby 3.0 or later
    > bundle exec jekyll serve
    
  2. Access http://localhost:4000
    The homepage will be displayed as shown below.
    By default, the minima theme is used.
    “Welcome to Jekyll!” is the page generated by the jekyll new command.
    Homepage

6. Commit and Push the Changes

  1. Modify .gitignore
    GitHub Pages does not install using Gemfile and Gemfile.lock.
    So add the following lines to the generated .gitignore:
    Gemfile
    Gemfile.lock
    
  2. Commit and push the changes.
    Open Command Prompt or PowerShell and run the following:
    > cd <path to the repository>
    > git add docs/
    > git commit -m "Add site created with Jekyll"
    > git push origin main
    

7. Change the Repository Settings

Modify the repository settings.

  1. Go to GitHub
  2. Open the page for your created GitHub repository.
    Link to access the GitHub repository page
  3. Click “Settings”
    Settings button
  4. Click “Pages”
    Pages button
  5. Under “Build and deployment,” change the root folder of the “Branch.”
    Select /docs.

8. View the Site

Check the published site.

  1. Go to GitHub
  2. Open the page for your created GitHub repository.
    Link to access the GitHub repository page
  3. Click “Settings”
    Settings button
  4. Click “Pages”
    Pages button
  5. Click “Visit site”
    Visit site button
    You will see the homepage.
    Homepage