Creating a Blog With GitHub Pages and Hugo
I created this blog using Hugo and host it on GitHub Pages. In this tutorial, I’ll teach you to do the same. The resources I had used to create a working blog left out some important details that I will include in my tutorial. I’ve also done the brunt of the work to perfect the theme and workflow. If you are like me, you can follow the tutorial that forks my site rather than making a blog site from scratch.
Prerequisites
- Hugo is “installed” and can be used (test
hugo version
) - git is installed and can be used (test
git version
) - If either test fails (i.e. not on PATH), learn from how to add to PATH
- VS Code + Hugo Helper extension
Forking My Blog
- Web UI fork blog.elijahlopez.ca with repository name
blog
and use your own description - Go to https://github.com/USERNAME/blog/settings/pages
- Select the source as
gh-pages
(you may need to create this branch) - For folder select
/
- Click save
- Add a custom domain if you want later since it takes 5+ minutes
- Edit the About section in https://github.com/USERNAME/blog/ and change the website to
https://USERNAME.github.io
or a domain - Clone your repo using
git clone --recurse-submodules -j8 https://github.com/USERNAME/blog.git
or GitHub desktop- also set
git config --global submodule.recurse true
- also set
- Delete
content/posts
andstatic/images
- Add your own
favicon.ico
tostatic/images
- Add your own
- Edit
hugo.yaml
and replace my information with yours- set
baseUrl
to the one shown by GitHub - change the
author
,email
, andsocial
- for a comment section, set up
Giscus
- Go to https://giscus.app
- Enter your repository
- Select a category
- Under Enable giscus, copy the IDs from the website’s script code into the
Giscus*
fields in thehugo.yaml
file
- set
- You can remove # to enable certain features (the about section requires uses
content/about.md
andcontent/about-subpage.md
) - Read
content/hugo-guide.md
in your new repo to help you write, edit, and publish posts
From Scratch
- Create a
USERNAME.github.io
repository in GitHub - Ensuring your articles publish
- Click “Actions” (beside Pull Request), “New workflow”, “Set up…”
- Enter the name “gh-pages.yml”
- Copy sample workflow from my repo
- If you’re default branch name (e.g. main) is not master, replace the two occurrences of master with your default branch name
- Save
- Clone your repository using
git clone https://...
- Get the GitHub link for a theme
- Add the theme using
git submodule add GitHubURL.git themes/themeName
- Read the theme instructions for basic configuration (i.e.
config.yaml
orconfig.toml
) - Edit
config.yaml
orconfig.toml
- Also add your own
favicon.ico
tostatic/images
- Also add your own
- Use
hugo new content/posts/POST.md
to create a new post- Alternative: use the hugo helpers, “Hugo: create content” command
- Use
hugo serve -D
when drafting the post and see your changes at http://localhost:1313/ - Set
draft: false
after you are done drafting a post - Add README.md with
git clone --recurse-submodules -j8 https://github.com/USERNAME/blog.git
clone instructions - Commit and push to origin (GitHub)
- To update your themes, use
git submodule update --remote --merge