How do I deploy a Hugo site to Netlify?

Reading Time: 2 minutes

TL;DR: Push your Hugo project to a Git repository, connect it to Netlify, set the build command to hugo and publish directory to public, pin your Hugo version, then deploy and add your custom domain.

Hugo plus Netlify is a dependable static pipeline, and setup is short if you avoid the two common traps.

Step 1 Make the project build locally

Run hugo server and confirm the site renders, then run hugo to produce the public directory. Fix local build errors before involving CI, because remote debugging is slower.

Step 2 Ignore generated output in Git

Initialise a repository and add a gitignore excluding public and resources. Commit content, configuration, layouts and theme files.

Step 3 Commit submodules properly

If your theme is a Git submodule, ensure it is committed correctly, otherwise the remote build fails with missing templates. This is one of the two classic traps.

Step 4 Push to your Git provider

Create a repository on GitHub, GitLab or Bitbucket and push. Netlify builds from the repository, so anything uncommitted simply does not exist in the deployed site.

Step 5 Connect the repository and set build settings

Create a new site from Git, authorise access and select the repository. Set the build command to hugo and the publish directory to public. Leave the base directory empty unless your project sits in a subfolder.

Step 6 Pin the Hugo version

Set HUGO_VERSION as an environment variable to the exact version you build with locally. This is the single most common cause of mysterious build failures, because the platform default drifts and Hugo occasionally introduces breaking changes.

Step 7 Deploy and check baseURL

Trigger the first deploy and read the build log. Missing assets usually indicate a baseURL mismatch, so set baseURL to your final domain before launch to keep canonical URLs, sitemaps and feeds correct.

Step 8 Add your domain and automate reviews

Attach your custom domain, let Netlify provision SSL, and confirm HTTPS resolves. Every push to production then deploys automatically. Enable deploy previews for branches if others contribute, so changes are reviewed before going live.

Back to How-To

Was this helpful?

Thanks for your feedback!

Comments are closed