Problem Link to heading
When a Hugo content file contains:
title: "My New Blog Post"
date: 2026-10-27
draft: true
Hugo treats the content as unpublished.
Running a standard build hugo will exclude all draft content from the generated site.
This behavior is intentional and helps prevent unfinished articles from being published accidentally.
To preview, hugo server -D.
The -D (or –buildDrafts) flag tells Hugo to include draft content during local development.
However, manually changing draft: true to draft: false before every commit is easy to forget.
Solution: Git Hooks Link to heading
A Git pre-commit hook can automatically update this status before commit.
Create a file .git/hooks/pre-commit
#!/bin/sh
#
# Auto-publish content on commit.
#
# Any staged Markdown file under content/ that still has `draft = true`
# is rewritten to `draft = false` and re-staged, so a push to main builds
# and deploys it.
#
# Installed via: git config core.hooksPath .githooks
set -e
git diff --cached --name-only --diff-filter=ACMR -- 'content' | while IFS= read -r f; do
case "$f" in
*.md) ;;
*) continue ;;
esac
[ -f "$f" ] || continue
if grep -qE '^[[:space:]]*draft[[:space:]]*=[[:space:]]*true[[:space:]]*$' "$f"; then
sed -i -E 's/^([[:space:]]*draft[[:space:]]*=[[:space:]]*)true[[:space:]]*$/\1false/' "$f"
git add -- "$f"
printf ' auto-publish: %s (draft = false)\n' "$f"
fi
done
Then the workflow becomes
hugo new content\posts\draft.md- edit
content\posts\draft.mdand preview - commit when ready