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 copies 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
Copying My Blog
- Create a repository like
$sub.$domain.$tldor$username.github.io(empty) - 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.ioor a domain - Clone your repo using
git clone --recurse-submodules -j8 https://github.com/USERNAME/blog.gitor GitHub desktop- also set
git config --global submodule.recurse true
- also set
- Click “Code” and then “Download ZIP” from github/elibroftw/blog.elijahlopez.ca
- Unzip my blog into your locally cloned repository.
- Delete dir
content/postsandcontent/authors - Recreate your default author using
hugo new authors/name-last.md - Edit
hugo.yamland replace my information with yours- set
baseUrlto 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.yamlfile
- set
- Add your own
favicon.icotostatic/images - You can remove # to enable certain features (the about section requires uses
content/about.mdandcontent/about-subpage.md) - Read
content/hugo-guide.mdin your new repo to help you write, edit, and publish posts
From Scratch
- Create a
USERNAME.github.iorepository 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.yamlorconfig.toml) - Edit
config.yamlorconfig.toml- Also add your own
favicon.icotostatic/images - Set
disableSummaryto false
- Also add your own
- Use
hugo new content/posts/POST.mdto create a new post- Alternative: use the hugo helpers, “Hugo: create content” command
- Use
hugo serve -Dwhen drafting the post and see your changes at http://localhost:1313/ - Set
draft: falseafter you are done drafting a post - Add README.md with
git clone --recurse-submodules -j8 https://github.com/USERNAME/blog.gitclone instructions - Commit and push to origin (GitHub)
- To update your themes, use
git submodule update --remote --merge
Other Resources
- https://gohugo.io/getting-started/quick-start/
- https://retrolog.io/blog/creating-a-hugo-theme-from-scratch/
- https://levelup.gitconnected.com/build-a-personal-website-with-github-pages-and-hugo-6c68592204c7
Troubleshooting
Note if you just installed git, you will need to set your username and email.
Set your username: git config --global user.name "FIRST_NAME LAST_NAME"
Set your email address: git config --global user.email "MY_NAME@example.com"