Step-By-Step-Guide: Deploy your Hugo-built static site online.

Last Updated: July 22, 2021

Follow these straightforward steps to deploy your static site built with Hugo for free.

Why this matters:

Though hosting a free static site sounds tempting, configuration & version tracking during deployment can be fraught with unforeseen difficulties.

Background

When selecting a static site generator our team were frustrated with the slow build time of Jekyll.

We eventually settled upon Hugo, the superfast framework built in Googles own language Go.

The motto of Hugo is build sites lightning fast & the build time doesn’t disappoint.

Deploying static sites are not at all straightforward & the options on the Hugo website don’t really offer anything that’s fast to setup & user friendly to maintain. Below is our guide to quickly deploying your Hugo site….

Assumptions & Prerequisites

  1. You have Hugo installed
  2. You’re ready to publish your content online.
  3. You have initialized your root folder with git & have made a number of commitments.

Steps:

  1. Ensure your baseURl is an empty string & not a url.
# config.yaml
title: "Pacifica Labs"
baseURL: ""  # note the absence of any url
languageCode: "en-AU"
  1. Ensure Hugo builds all your content from scratch by removing your public folder:
rm -rf public/
  1. Build your static site content
$ hugo
Start building sites …

                   | EN
-------------------+-----
  Pages            | 21
  Paginator pages  |  0
  Non-page files   |  0
  Static files     | 18
  Processed images | 16
  Aliases          |  6
  Sitemaps         |  1
  Cleaned          |  0

Total in 263 ms
  1. You will see newly compiled content in the public folder:
$ ls public/

404.html
about
articles
blog
docs
favicon.ico
fonts
gallery
index.html
(...)
(...)
(...)
(etc)
  1. Create an empty repository on github and commit your entire project folder:

git add .

git commit -m "first commit"
  1. Create a new branch called gh-pages which is the branch github pages will read from when deploying the static site:

  2. Create a subtree

git push origin `git subtree split --prefix public master`:gh-pages --force
  1. Wait til the pages notification changes from blue to green

  2. Confirm your changes!

The Big Picture:

Key steps in deploying a Hugo repository require subtree usage.

Go Deeper…

(Further reading links here) This is a bash script I have written to automate the above steps of the deployment process.

Appendix

  1. The top 4 global static site generators were Next.js, Hugo & Gatsby & Jekyll.
  2. In benchmarking tests Hugo compiled 23x faster than Jekyll.