Hosting a Hugo Blog on Github for Free with Pages and Actions

I’ve recently started a new blog using the static-site generator and HN-favourite, hugo. Hugo lets your write your posts and site content as markdown files which you can check into source control. From this, you can build and deploy raw files to humble static hosting.

There are many ways to build a deployment pipeline. I have seen people build and check-in artifacts manually or use a paid service to handle this. However, nothing costly or irriating is neccessary.

Step 1: Actions

Assuming you have a repository containing your hugo blog files, all you have to do is add this script to .github/workflows/deploy.yml. If your blog uses a master branch or any other, change it accordingly.

            - main

        runs-on: ubuntu-latest

            - uses: actions/checkout@v2
                  submodules: true

            - run: sudo snap install hugo

            - run: hugo

            - uses: JamesIves/github-pages-deploy-action@v4
                  branch: gh-pages
                  folder: public

Step 2: Pages

Now just make sure pages is deploying from your gh-pages branch. Our script will take source files from master, build them, and commit the result to gh-pages.

Github Pages Sources

Step 3: Enjoy

All you have to do now is write the content. Good luck.