JanDeDobbeleer/oh-my-posh · warning

git config file not found

Error message

git config file not found

What it means

getGitConfig lazily loads the current repository's .git/config file with a sync.Once. If g.fileContent returns an empty string (file missing or unreadable), it caches and returns the sentinel error "git config file not found". This typically means the segment isn't operating inside a valid git worktree or the config file can't be read.

Source

Thrown at src/segments/git.go:751

	section := cfg.Section(sectionName)
	pushRemote := section.Key("pushRemote").String()
	if pushRemote == "" {
		pushRemote = cfg.Section("remote").Key("pushDefault").String()
	}

	if pushRemote == "" {
		pushRemote = upstream
	}

	return pushRemote + "/" + branch
}

func (g *Git) getGitConfig() (*ini.File, error) {
	g.configOnce.Do(func() {
		configData := g.fileContent(g.mainSCMDir, "config")
		if configData == "" {
			log.Debug("git config file not found")
			g.configErr = fmt.Errorf("git config file not found")
			return
		}

		cfg, err := ini.Load(configData)
		if err != nil {
			g.configErr = err
			return
		}

		g.config = cfg
	})

	return g.config, g.configErr
}

func (g *Git) cleanUpstreamURL(url string) string {
	// Azure DevOps
	if strings.Contains(url, "dev.azure.com") {

View on GitHub (pinned to 0976794618)

Solutions

  1. cd into a valid git repository (verify .git/config exists) - the segment is meant for repos.
  2. Check that the repo's .git/config file is readable by the user running the shell (permissions).
  3. If using a worktree/submodule, verify the .git pointer file resolves to a real git dir containing config.
  4. Because the result is cached in configErr via sync.Once, restart the shell if you fixed the repo mid-session so the segment re-reads config.
Defensive patterns

Strategy: fallback

Validate before calling

// Before enabling the git segment, confirm a repo is present
if _, err := os.Stat(filepath.Join(cwd, ".git")); os.IsNotExist(err) {
    // not a git repo: disable segment
}

Try / catch

cfg, err := gitSegment.getGitConfig()
if err != nil && err.Error() == "git config file not found" {
    // not in a repo (or unreadable config): fall back to non-git prompt
    return defaultPrompt
}

Prevention

When it happens

Trigger: The git segment (fetch/Enabled path) queries config values while mainSCMDir points to a directory without a readable "config" file - e.g. not in a repo, a bare/partial clone layout change, or permission problems reading .git/config.

Common situations: Prompt rendered outside any git repository; .git directory deleted or renamed; running as a user without read access to the repo; a broken .git file (worktree pointer) so mainSCMDir resolves to a nonexistent path.

Related errors


AI-assisted analysis of JanDeDobbeleer/oh-my-posh@0976794618 (2026-08-31). Data as JSON: /api/errors/cde755bd040806a1. Report an issue: GitHub.