gastownhall/beads · error
failed to pin target git marker identity: %w
Error message
failed to pin target git marker identity: %w
What it means
bd pins the worktree's `.git` marker file (the plain-text file inside a linked worktree pointing at its gitdir) via `os.Lstat` before removal. This error means the marker could not be stat'ed at all — it is missing or unreadable — so bd cannot verify the target is a genuine, intact linked worktree.
Source
Thrown at cmd/bd/worktree_cmd.go:1021
}
pathInfo, err := os.Lstat(worktree.path)
if err != nil {
return pinnedWorktreeTarget{}, fmt.Errorf("failed to pin target directory identity: %w", err)
}
if pathInfo.Mode()&os.ModeSymlink != 0 || !pathInfo.IsDir() {
return pinnedWorktreeTarget{}, fmt.Errorf("target path is not a real directory: %s", worktree.path)
}
gitDirInfo, err := os.Lstat(gitDir)
if err != nil {
return pinnedWorktreeTarget{}, fmt.Errorf("failed to pin target git directory identity: %w", err)
}
if gitDirInfo.Mode()&os.ModeSymlink != 0 || !gitDirInfo.IsDir() {
return pinnedWorktreeTarget{}, fmt.Errorf("target git directory is not a real directory: %s", gitDir)
}
gitMarkerPath := filepath.Join(worktree.path, ".git")
gitMarkerInfo, err := os.Lstat(gitMarkerPath)
if err != nil {
return pinnedWorktreeTarget{}, fmt.Errorf("failed to pin target git marker identity: %w", err)
}
if gitMarkerInfo.Mode()&os.ModeSymlink != 0 || !gitMarkerInfo.Mode().IsRegular() {
return pinnedWorktreeTarget{}, fmt.Errorf("target git marker is not a regular file: %s", gitMarkerPath)
}
gitDirFingerprint, err := fingerprintWorktreeFilesystem(gitDir)
if err != nil {
return pinnedWorktreeTarget{}, fmt.Errorf("failed to fingerprint target git directory: %w", err)
}
gitMarkerFingerprint, err := fingerprintWorktreeFilesystem(gitMarkerPath)
if err != nil {
return pinnedWorktreeTarget{}, fmt.Errorf("failed to fingerprint target git marker: %w", err)
}
statusFingerprint, err := fingerprintWorktreeStatusPaths(worktree.path, string(statusOutput))
if err != nil {
return pinnedWorktreeTarget{}, fmt.Errorf("failed to fingerprint target changes: %w", err)
}
return pinnedWorktreeTarget{View on GitHub (pinned to 71377f2769)
Solutions
- Verify `<worktree>/.git` exists and is readable: `ls -la <worktree>/.git`; recreate it (`echo "gitdir: /repo/.git/worktrees/<name>" > .git`) if deleted
- Run `git worktree repair` from the main repository to restore links
- If the worktree is unwanted, delete the directory manually and run `git worktree prune`
Example fix
// before: marker missing, removal fails // after: repair registration cd /repo && git worktree repair && bd worktree remove mywt
Defensive patterns
Strategy: validation
Validate before calling
if _, err := os.Lstat(filepath.Join(worktreePath, ".git")); err != nil {
return fmt.Errorf("refusing: worktree marker missing: %w", err)
} Type guard
func hasGitMarker(worktreePath string) bool {
_, err := os.Lstat(filepath.Join(worktreePath, ".git"))
return err == nil
} Prevention
- Never delete the `.git` pointer file inside a linked worktree
- Run `git worktree repair` after moving repositories
- Verify worktree integrity with `git worktree list` before batch operations
When it happens
Trigger: `bd worktree remove <name>` or observeRevalidation when `<worktree path>/.git` does not exist or cannot be lstat'ed (permission denied, deleted while bd ran, I/O error).
Common situations: Deleting the `.git` file inside a linked worktree; running removal after a partially-failed cleanup; read-only or inaccessible worktree directories; Windows/network mounts hiding the file.
Related errors
- target git directory is not a real directory: %s
- cannot safely prepare .gitignore cleanup: %w
- target directory identity changed
- target git directory identity changed
- target git marker identity changed
AI-assisted analysis of gastownhall/beads@71377f2769 (2026-08-30).
Data as JSON: /api/errors/1bacbcb5add68d3d.
Report an issue: GitHub.