dagger/dagger · error
find git ref: %w
Error message
find git ref: %w
What it means
currentGitRef wraps a failure of `git rev-parse HEAD` with the message "find git ref: ...". It is reached only when `git symbolic-ref --quiet --short HEAD` fails (detached HEAD or not a git repo) AND the fallback `git rev-parse HEAD` also fails. This means the directory is not a valid git repository or has no commits at all.
Source
Thrown at internal/cmd/dagger/workspace.go:975
return workspaceRemoteAddress{}, "", false, err
}
if !ok {
return workspaceRemoteAddress{}, "", false, fmt.Errorf("inferred git origin %q is not a remote workspace address", info.cloneRef)
}
return remote, inferred, false, nil
}
// This is intentionally narrower than the workspace-git API: it only projects
// a local checkout into a copy/pasteable remote workspace address, without
// starting the engine or modeling full Git state.
func currentGitRef(ctx context.Context, repoRoot string) (string, error) {
ref, err := gitOutput(ctx, repoRoot, "symbolic-ref", "--quiet", "--short", "HEAD")
if err == nil && ref != "" {
return ref, nil
}
sha, err := gitOutput(ctx, repoRoot, "rev-parse", "HEAD")
if err != nil {
return "", fmt.Errorf("find git ref: %w", err)
}
return sha, nil
}
func currentGitCommit(ctx context.Context, repoRoot string) (string, error) {
sha, err := gitOutput(ctx, repoRoot, "rev-parse", "--verify", "HEAD")
if err != nil {
return "", fmt.Errorf("find git commit: %w", err)
}
return sha, nil
}
func gitWorktreeDirty(ctx context.Context, repoRoot string) (bool, error) {
status, err := gitOutput(ctx, repoRoot, "status", "--porcelain")
if err != nil {
return false, fmt.Errorf("check git status: %w", err)
}
return status != "", nilView on GitHub (pinned to 82ba2681db)
Solutions
- Commit at least once in the repository (git commit) so HEAD resolves
- Verify you are in a git repo: run `git rev-parse HEAD` yourself and fix per its message
- Re-initialize or repair the repo: git init / git clone the project
- Point the command at the correct repo root directory
Example fix
// shell # before: fresh git init, no commit -> error # after git init && git add . && git commit -m initial
Defensive patterns
Strategy: validation
Validate before calling
if _, err := os.Stat(filepath.Join(repoRoot, ".git")); err != nil {
return fmt.Errorf("%s is not a git repository", repoRoot)
}
out, err := exec.CommandContext(ctx, "git", "-C", repoRoot, "rev-parse", "HEAD").CombinedOutput()
if err != nil {
return fmt.Errorf("git repo has no commits: %s", out)
} Type guard
func hasGitCommits(ctx context.Context, dir string) bool {
return exec.CommandContext(ctx, "git", "-C", dir, "rev-parse", "--verify", "HEAD").Run() == nil
} Try / catch
ref, err := currentGitRef(ctx, repoRoot)
if errors.Is(err, exec.ErrNotFound) || strings.Contains(err.Error(), "not a git repository") {
// fall back to non-git workspace handling
} Prevention
- Always run inside a committed git repository
- Add a pre-flight `git rev-parse --verify HEAD` check in CI scripts
- Avoid CI checkouts that strip .git metadata
When it happens
Trigger: Running `dagger` workspace commands in a directory where .git is missing, corrupted, or where the repo has no commits (fresh `git init` with nothing committed), so rev-parse HEAD fails.
Common situations: Running in a freshly initialized repo before the first commit; running outside any repo; a corrupted .git directory; running in a CI workspace checked out without git metadata.
Related errors
- find git commit: %w
- --workspace must be a local path for %q
- %s requires a remote workspace selected with -W or a local w
- %s only supports remote workspaces or local git workspaces;
- check git status: %w
AI-assisted analysis of dagger/dagger@82ba2681db (2026-09-05).
Data as JSON: /api/errors/b212017ce85279d2.
Report an issue: GitHub.