mislav/hub · critical

error running git version: %s

Error message

error running git version: %s

What it means

Version() runs `git version` via exec.Command().Output() and wraps any failure of the git binary invocation into this error. It means the library could not execute git (or git exited non-zero), so it cannot report the git version string. This is an environment/toolchain problem, not a code problem.

Source

Thrown at git/git.go:18

package git

import (
	"fmt"
	"os"
	"path/filepath"
	"strings"

	"github.com/github/hub/v2/cmd"
)

var GlobalFlags []string

func Version() (string, error) {
	versionCmd := gitCmd("version")
	output, err := versionCmd.Output()
	if err != nil {
		return "", fmt.Errorf("error running git version: %s", err)
	}
	return firstLine(output), nil
}

var cachedDir string

func Dir() (string, error) {
	if cachedDir != "" {
		return cachedDir, nil
	}

	dirCmd := gitCmd("rev-parse", "-q", "--git-dir")
	dirCmd.Stderr = nil
	output, err := dirCmd.Output()
	if err != nil {
		return "", fmt.Errorf("Not a git repository (or any of the parent directories): .git")
	}

View on GitHub (pinned to 5c547ed804)

Solutions

  1. Install git or add it to PATH (e.g. apt-get install git / ensure /usr/bin/git exists)
  2. Verify manually with `git version` in the same environment the tool runs in
  3. Check the PATH of the process (systemd services/CI often have a minimal PATH)
  4. Inspect the wrapped %s error for the underlying exec detail

Example fix

// before: assume git exists
version, _ := git.Version()
// after: check availability first
if _, err := exec.LookPath("git"); err != nil {
    return fmt.Errorf("git is not installed or not in PATH: %w", err)
}
version, err := git.Version()
if err != nil {
    return err
}
Defensive patterns

Strategy: validation

Validate before calling

if _, err := exec.LookPath("git"); err != nil {
    return fmt.Errorf("git binary required but not found in PATH")
}

Try / catch

version, err := git.Version()
if err != nil {
    return fmt.Errorf("git unavailable: %w", err)
}

Prevention

When it happens

Trigger: Calling git.Version() when the git binary is not installed, not on PATH, not executable, or otherwise fails to run `git version` (e.g. corrupted install, exec format issue).

Common situations: Fresh containers/CI images without git installed; PATH not set up in the process environment; restricted environments where spawning processes is blocked; broken git installation.

Related errors


AI-assisted analysis of mislav/hub@5c547ed804 (2026-09-01). Data as JSON: /api/errors/455a4ea06b42d0f5. Report an issue: GitHub.