Hugo Blogging Setup

This website is built with hugo and hosted with github pages. Github Pages hosts the files in the /docs folder of the repository on

I have to run hugo to update the /docs folder, and I always forget to do it. The problem is that I'm very used to quickly typing git add . then git commit and git push without ever running hugo. To deal with it, I've built the following pre-commit and post-commit hooksI really don't reccomend doing something like this for code repos. But this repository is just for writing some prose notes. I value being able to quickly write out a new note, or make a quick correction, then get back to work. One of the main problems I found before moving to this solution was that I'd just keep banging on, refreshing until GitHub would update it minutes later. This hack saves me a bit of time, but much more importantly it keeps me in the zone and keeps me from having to worry about whether I successfully published to github. to automatically run hugo, add the results of hugo to git, then (in a post-commit) attempt to amend our git commit with our added files when I commit.


# run `hugo` and add the results to ./docs before comiting
git add ./docs/*

Then I have a post-commit hook to ammend my commit while using the same message:


# Amend the commit to include anything generated by the pre-commit hook
# If we don't setup this conditional, we'll get into an infinite loop of post-commits
# since the amended git-commit will trigger this same post-commit.
if [[ -z "${SKIP_POST_COMMIT}" ]]; then
  echo "Skipping Commit. Amended"
  SKIP_POST_COMMIT=true git commit --amend --no-verify --no-edit

Remember you need to make your git hooks executable:

git chmod +x .git/hooks/pre-commit
git chmod +x .git/hooks/post-commit