gohugoio/hugo · error
failed to load Git data: %w
Error message
failed to load Git data: %w
What it means
When `enableGitInfo` is active, Hugo attaches per-file Git metadata (last commit, author, date) to each page during page construction (`newPageFromMeta`). If `gitInfoForPage` fails — typically because the git log for the content file cannot be read or parsed — page creation aborts with this wrapped error.
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 8a468df065)
Solutions
- In CI, fetch full history — e.g. GitHub Actions `actions/checkout` with `fetch-depth: 0` — and ensure `.git` is present in the build context.
- Verify `git log -- <content-file>` works from the project root the build runs in.
- If Git metadata isn't needed in that environment, disable it: remove `enableGitInfo = true` or drop the `--enableGitInfo` flag for that build.
Example fix
# before (.github/workflows/build.yml)
- uses: actions/checkout@v4
# after
- uses: actions/checkout@v4
with:
fetch-depth: 0 Defensive patterns
Strategy: validation
Validate before calling
# Before enabling enableGitInfo = true, verify the site is a real, non-shallow repo: git -C ./site rev-parse --is-inside-work-tree git -C ./site rev-parse --is-shallow-repository # must be false
Try / catch
if err := build(); err != nil {
if strings.Contains(err.Error(), "failed to load Git data") {
log.Println("disable enableGitInfo or fetch full git history (fetch-depth: 0 in CI)")
}
return err
} Prevention
- Only set enableGitInfo=true when building inside a git working tree
- In CI, clone with full history (actions/checkout fetch-depth: 0) so git log works per file
- Ensure the git binary is on PATH in the build environment
- Don't build from exported tarballs/artifacts with GitInfo enabled
When it happens
Trigger: Building with `enableGitInfo = true` (or `--enableGitInfo`) when the working directory is not a usable git repository for the content file: `git` history is unavailable for the file's path, the gitmap scan of `git log` fails, or the repo state is unreadable at build time.
Common situations: CI systems doing shallow clones (`fetch-depth: 1` in GitHub Actions) so history is incomplete or the `.git` dir is absent in the build container; content mounted from outside the repo; Docker builds that copy sources without `.git`; submodule or worktree setups where the content path isn't covered by the repo.
Related errors
- failed to clone %s: %v
- failed to map git repo for module %s: %v
- git clone %s: %w: %s
- no Dart Sass binary found in $PATH
- failed to fetch remote resource from '%s': %s
AI-assisted analysis of gohugoio/hugo@8a468df065 (2026-07-31).
Data as JSON: /data/errors/74c1c28316ea6932.json.
Report an issue: GitHub ↗.