mislav/hub · error
Can't load git var: GIT_EDITOR
Error message
Can't load git var: GIT_EDITOR
What it means
Editor() runs `git var GIT_EDITOR` to resolve which editor git would use, then expands any env vars in the result. The error is thrown when that subprocess fails — i.e. git could not resolve GIT_EDITOR (often because neither GIT_EDITOR, core.editor, VISUAL, EDITOR is set and git falls back to a check that fails).
Source
Thrown at git/git.go:112
return false
}
s := []string{dir}
s = append(s, segments...)
path := filepath.Join(s...)
if _, err := os.Stat(path); err == nil {
return true
}
return false
}
func Editor() (string, error) {
varCmd := gitCmd("var", "GIT_EDITOR")
varCmd.Stderr = nil
output, err := varCmd.Output()
if err != nil {
return "", fmt.Errorf("Can't load git var: GIT_EDITOR")
}
return os.ExpandEnv(firstLine(output)), nil
}
func Head() (string, error) {
return SymbolicRef("HEAD")
}
// SymbolicRef reads a branch name from a ref such as "HEAD"
func SymbolicRef(ref string) (string, error) {
refCmd := gitCmd("symbolic-ref", ref)
refCmd.Stderr = nil
output, err := refCmd.Output()
return firstLine(output), err
}
// SymbolicFullName reads a branch name from a ref such as "@{upstream}"View on GitHub (pinned to 5c547ed804)
Solutions
- Export an editor: export GIT_EDITOR=vim (or core.editor in git config)
- Set EDITOR/VISUAL in the environment (e.g. in Dockerfile or CI setup step)
- Verify with `git var GIT_EDITOR` in the same shell
- Alternatively use the EDITOR env var directly if the library consumer controls it
Example fix
// before: assume editor resolves
editor, _ := git.Editor()
// after: ensure an editor is configured
if os.Getenv("GIT_EDITOR") == "" && os.Getenv("EDITOR") == "" {
os.Setenv("GIT_EDITOR", "vim")
}
editor, err := git.Editor() Defensive patterns
Strategy: fallback
Validate before calling
if os.Getenv("GIT_EDITOR") == "" && os.Getenv("EDITOR") == "" && os.Getenv("VISUAL") == "" {
os.Setenv("GIT_EDITOR", "vim") // or vi/nano depending on platform
} Try / catch
editor, err := git.Editor()
if err != nil {
editor = os.Getenv("EDITOR")
if editor == "" { editor = "vi" }
} Prevention
- Set GIT_EDITOR or EDITOR in CI images and containers
- Configure core.editor in git config for reproducible behavior
- Use non-interactive editors (true/vim -e) in automated flows
- Test `git var GIT_EDITOR` in deployment environments
When it happens
Trigger: Calling git.Editor() (directly or via TestGitEditor/NewEditor) in an environment where `git var GIT_EDITOR` exits non-zero: no editor env var configured and no sensible default available.
Common situations: CI/headless servers with no EDITOR or GIT_EDITOR set; Docker containers; running under a service account with a minimal environment; git versions where `git var` errors instead of returning a default.
Understand the failure class
Background: "environment variable is not set" and "Missing keys in environment" errors: what missing required env var messages mean and how to fix them — this error's family across 28 libraries.
Related errors
- Please set $BROWSER to a web launcher
- 'create' must be run from inside a git repository
- error running git version: %s
- Not a git repository (or any of the parent directories): .gi
- error using text editor for %s message
AI-assisted analysis of mislav/hub@5c547ed804 (2026-09-01).
Data as JSON: /api/errors/03436c071a8c12f2.
Report an issue: GitHub.