{"record":{"id":"1e0231608fc9b401","repo":"dagger/dagger","slug":"failed-to-checkout-remote-s-w","errorCode":null,"errorMessage":"failed to checkout remote %s: %w","messagePattern":"failed to checkout remote (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/git.go","lineNumber":948,"sourceCode":"\ttmpref := \"refs/dagger.tmp/\" + identity.NewID()\n\n\t// TODO: maybe this should use --no-tags by default, but that's a breaking change :(\n\t// also, we currently don't do any special work to ensure that the fetched\n\t// tags are consistent with the GitRepository.Remote (oops)\n\targs := []string{\"fetch\", \"-u\"}\n\tif depth > 0 {\n\t\targs = append(args, fmt.Sprintf(\"--depth=%d\", depth))\n\t}\n\targs = append(args, cloneURL)\n\targs = append(args, ref.SHA+\":\"+tmpref)\n\t_, err = checkoutGit.Run(ctx, args...)\n\tif err != nil {\n\t\treturn err\n\t}\n\tif ref.Name == \"\" {\n\t\t_, err = checkoutGit.Run(ctx, \"checkout\", ref.SHA)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"failed to checkout remote %s: %w\", cloneURL, err)\n\t\t}\n\t} else {\n\t\t_, err = checkoutGit.Run(ctx, \"update-ref\", ref.Name, ref.SHA)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"failed to checkout remote %s: %w\", cloneURL, err)\n\t\t}\n\t\t_, err = checkoutGit.Run(ctx, \"checkout\", strings.TrimPrefix(ref.Name, \"refs/heads/\"))\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"failed to checkout remote %s: %w\", cloneURL, err)\n\t\t}\n\t\t_, err = checkoutGit.Run(ctx, \"reset\", \"--hard\", ref.SHA)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"failed to reset ref: %w\", err)\n\t\t}\n\t}\n\tif remoteURL != \"\" {\n\t\t_, err = checkoutGit.Run(ctx, \"remote\", \"add\", \"origin\", remoteURL)\n\t\tif err != nil {","sourceCodeStart":930,"sourceCodeEnd":966,"githubUrl":"https://github.com/dagger/dagger/blob/82ba2681dbe30d3547a1dc50ea495900ab5b6047/core/git.go#L930-L966","documentation":"After fetching the requested SHA into a temp ref, doGitCheckout checks out that SHA directly when no branch name is present (detached checkout). \"failed to checkout remote\" wraps the git checkout failure, meaning the object was fetched but git could not materialize it as HEAD.","triggerScenarios":"Querying a GitRepository by SHA only (ref.Name == \"\") and `git checkout <sha>` fails in the freshly-initialized checkout dir — the fetch of that SHA likely failed, was shallow-pruned, or the repo state is inconsistent.","commonSituations":"Requesting a commit SHA that was force-pushed away or is unreachable on the remote; shallow-clone depth too small to include the SHA; server-side uploadpack.allowReachableSHA1InWant restrictions; corrupted fetch.","solutions":["Verify the SHA still exists and is reachable on the remote (`git fetch <url> <sha>` locally)","Increase the clone depth or use a full fetch so the SHA is present in the object store","Use a branch/tag ref instead of a bare SHA if possible","Re-run with the updated SHA if the branch was force-pushed"],"exampleFix":"// before: bare force-pushed SHA\ngit(ref: \"a1b2c3deadbeef...\")\n// after: reference the branch and let Dagger resolve HEAD\ngit(ref: \"main\")","handlingStrategy":"retry","validationCode":"// confirm the SHA is fetchable before requesting it\n// git ls-remote <url> does not list raw SHAs, so pre-fetch instead:\n// git fetch <url> <sha> && git cat-file -e <sha>^{commit}","typeGuard":null,"tryCatchPattern":"tree, err := repo.Commit(sha).Tree()\nif err != nil && strings.Contains(err.Error(), \"failed to checkout remote\") {\n\t// retry after re-resolving the branch head (likely force-pushed)\n\tsha, _ = repo.Branch(\"main\").CommitID(ctx)\n\ttree, err = repo.Commit(sha).Tree()\n}","preventionTips":["Resolve branch heads shortly before use instead of caching SHAs","Avoid bare SHAs on remotes without uploadpack.allowReachableSHA1InWant","Use branch/tag refs when exact-SHA pinning is not required"],"tags":["git","checkout","network"],"backgroundTag":"git-checkout-failed","analyzedSha":"82ba2681dbe30d3547a1dc50ea495900ab5b6047","analyzedAt":"2026-09-05T07:21:37.930Z","contentChangedAt":"2026-09-05T07:21:37.930Z","schemaVersion":2},"datasetVersion":"2026-09-12T12:17:11.808Z"}