mislav/hub · critical · exec.Error

command not found

Error message

command not found

What it means

In hub's Exec, before running a git command it calls exec.LookPath(cmd.Name). If the binary cannot be found on PATH it wraps the failure in an exec.Error with a generic "command not found" message, naming the missing command. This is hub's way of reporting that an external program (usually git) required to run the command is not installed or not on PATH.

Source

Thrown at cmd/cmd.go:125

	verboseLog(cmd)
	c := exec.Command(cmd.Name, cmd.Args...)
	c.Stdin = cmd.Stdin
	c.Stdout = cmd.Stdout
	c.Stderr = cmd.Stderr

	return c.Run()
}

// Exec runs command with exec(3)
// Note that Windows doesn't support exec(3): http://golang.org/src/pkg/syscall/exec_windows.go#L339
func (cmd *Cmd) Exec() error {
	verboseLog(cmd)

	binary, err := exec.LookPath(cmd.Name)
	if err != nil {
		return &exec.Error{
			Name: cmd.Name,
			Err:  fmt.Errorf("command not found"),
		}
	}

	args := []string{binary}
	args = append(args, cmd.Args...)

	return syscall.Exec(binary, args, os.Environ())
}

func New(name string) *Cmd {
	return &Cmd{
		Name:   name,
		Args:   []string{},
		Stdin:  os.Stdin,
		Stdout: os.Stdout,
		Stderr: os.Stderr,
	}
}

View on GitHub (pinned to 5c547ed804)

Solutions

  1. Install git (apt-get install git / brew install git) or verify `which git` succeeds.
  2. Fix PATH in the execution environment so it includes /usr/bin (or wherever git lives).
  3. If invoking hub from scripts/CI, export PATH explicitly before calling hub.

Example fix

// before: minimal Dockerfile
FROM scratch
COPY hub /usr/bin/hub
// after
FROM alpine
RUN apk add --no-cache git
COPY hub /usr/bin/hub
Defensive patterns

Strategy: validation

Validate before calling

if ! command -v git >/dev/null 2>&1; then
  echo "git is required by hub" >&2
  exit 1
fi

Prevention

When it happens

Trigger: Any hub command that shells out to git (nearly all of them) when git isn't installed or PATH is stripped (e.g. cron, CI container, minimal Docker image).

Common situations: git missing from the container image; PATH not inherited when hub is invoked from a cron job or systemd service; broken PATH after custom shell config; git uninstalled/upgraded mid-session.

Related errors


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