A static blog holds only HTML, CSS, and image files. It has no database. It also has no server-side programming language. This very blog is an example. All of it is just HTML and CSS files. Anyone can open it over the internet. The hosting is free. It uses GitHub Pages. GitHub Pages is a free hosting service from GitHub.

How to deploy a blog to GitHub Pages

Figure 1: The static blog deployment flow to GitHub Pages — from blog files to a live blog.

What You Need

  • A GitHub account (free, sign up at github.com).
  • Your blog files — at minimum index.html.
  • A browser.

Step 1: Create a Repository

A repository is a place to store project files on GitHub. Log in to GitHub first. Click the + button at the top right. Choose New repository. Fill in Repository name with username.github.io. Replace username with your GitHub username. Choose Public. Click Create repository.

username.github.io

            username.github.io

Tip: If you want to make a second blog, the repository name is up to you, for example blog-saya. Its address will then be username.github.io/blog-saya.

Step 2: Upload the Blog Files

Open your repository page. Click Add file, then Upload files. Drag the index.html file, the css folder, and the img folder there. Click Commit changes. The index.html file is required. That file is your blog’s home page.

The blog repository’s contents

Figure 2: Example of a blog repository’s contents — the index.html file is required.

If you’re already comfortable with Git, you can push via the terminal. Git is a tool for sending files to GitHub from your computer. A terminal is a place to type text commands on your computer.

git init

            git add .

            git commit -m "Blog pertama"

            git remote add origin https://github.com/username/username.github.io.git

            git push -u origin main

            git init

            git add .

            git commit -m "Blog pertama"

            git remote add origin https://github.com/username/username.github.io.git

            git push -u origin main

Warning: Don’t upload secret files like passwords or API keys to a public repository. An API key is a secret code for using a service. Everyone can see the contents of a public repository.

Step 3: Enable GitHub Pages

Go to the Settings tab in your repository. Choose Pages in the left menu. In the Branch section, choose main and the / (root) folder. Click Save.

Step 4: Open Your Blog

Wait 1–2 minutes until GitHub finishes building your blog. Then open its address:

https://username.github.io/

            https://username.github.io/

Tip: If the page hasn’t appeared yet, wait a moment and then refresh. The first GitHub Pages build usually takes 1–2 minutes.

Update the Blog

To change the blog’s content, edit the files directly on GitHub. You can also push again via Git. GitHub Pages will rebuild your blog automatically within 1–2 minutes.

References

  1. https://docs.github.com/en/pages/getting-started-with-github-pages
  2. https://docs.github.com/en/pages/quickstart