gohugoio/hugo · error

failed to load Git data

Error message

failed to load Git data: %w

What it means

Raised during page creation (page__new.go:90) when Hugo fails to assemble Git authoring metadata for a page file. It delegates to HugoSites.gitInfoForPage which runs the one-shot loadGitInfo (hugo_sites.go:546) gated by enableGitInfo; the inner newGitInfo (gitinfo.go:110) maps the local repo and any Git submodule modules. The wrapped error is the underlying git/gitmap failure.

Solutions

  1. Ensure the project root is an initialized Git repo (`git status` works) and that `git` is on PATH in the build environment.
  2. If you do not need Git metadata, remove or set `enableGitInfo = false` in hugo.toml.
  3. For shallow CI clones, fetch full history or disable enableGitInfo for that pipeline.
  4. If a Hugo module remote is involved, verify network/proxy access and run `hugo mod vendor` to remove the runtime fetch.

Example fix

# before
# hugo.toml
enableGitInfo = true
# built in a CI checkout with depth=1 and no .git

# after: either give it real history
git fetch --unshallow
# or turn the feature off
enableGitInfo = false
Defensive patterns

Strategy: validation

Validate before calling

# Validate preconditions before invoking hugo with enableGitInfo.
test -d .git || { echo "not a git repo"; exit 1; }
command -v git >/dev/null || { echo "git not installed"; exit 1; }
git rev-parse --is-inside-work-tree >/dev/null 2>&1 || exit 1

Prevention

When it happens

Trigger: enableGitInfo = true is set but the project directory is not inside a Git repository; the git binary is missing from PATH; a Hugo module points to a remote that cannot be cloned/fetched; the local repo log read fails (corrupt repo, shallow clone issues, permission denied on .git).

Common situations: CI builds that check out shallow clones or detached trees without .git; building on a fresh machine where git is not installed; a submodule mount whose origin URL is unreachable behind a proxy; switching a project to enableGitInfo after the fact without running `git init`.

Related errors


AI-assisted analysis of gohugoio/hugo@52c9bd7908 (2026-08-09). Data as JSON: /api/errors/74c1c28316ea6932. Report an issue: GitHub.

Appendix: source

Thrown at hugolib/page__new.go:90

			ShortcodeInfoProvider:      page.NopPage,
			LanguageProvider:           s,
			RelatedDocsHandlerProvider: s,
			m:                          m,
			s:                          s,
		},
	}

	if ps.IsHome() && ps.PathInfo().IsLeafBundle() {
		msg := "Using %s in your content's root directory is usually incorrect for your home page. "
		msg += "You should use %s instead. If you don't rename this file, your home page will be "
		msg += "treated as a leaf bundle, meaning it won't be able to have any child pages or sections."
		ps.s.Log.Warnidf(constants.WarnHomePageIsLeafBundle, msg, ps.PathInfo().PathNoLeadingSlash(), strings.ReplaceAll(ps.PathInfo().PathNoLeadingSlash(), "index", "_index"))
	}

	if m.f != nil {
		gi, err := s.h.gitInfoForPage(ps)
		if err != nil {
			return nil, fmt.Errorf("failed to load Git data: %w", err)
		}
		ps.gitInfo = gi
		owners, err := s.h.codeownersForPage(ps)
		if err != nil {
			return nil, fmt.Errorf("failed to load CODEOWNERS: %w", err)
		}
		ps.codeowners = owners
	}

	ps.pageMenus = &pageMenus{p: ps}
	ps.PageMenusProvider = ps.pageMenus
	ps.GetPageProvider = pageSiteAdapter{s: s, p: ps}
	ps.GitInfoProvider = ps
	ps.TranslationsProvider = ps
	ps.ResourceDataProvider = newDataFunc(ps)
	ps.RawContentProvider = ps
	ps.ChildCareProvider = ps
	ps.TreeProvider = pageTree{p: ps}

View on GitHub (pinned to 52c9bd7908)