{"record":{"id":"fa64769f5278e1a2","repo":"lima-vm/lima","slug":"repository-s-s-has-no-default-branch","errorCode":null,"errorMessage":"repository %s/%s has no default branch","messagePattern":"repository (.+?)/(.+?) has no default branch","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/limatmpl/github.go","lineNumber":144,"sourceCode":"\t}\n\tdefer resp.Body.Close()\n\n\tbody, err := io.ReadAll(resp.Body)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"failed to read GitHub API response: %w\", err)\n\t}\n\tif resp.StatusCode != http.StatusOK {\n\t\treturn \"\", fmt.Errorf(\"GitHub API returned status %d: %s\", resp.StatusCode, string(body))\n\t}\n\n\tvar repoData struct {\n\t\tDefaultBranch string `json:\"default_branch\"`\n\t}\n\tif err := json.Unmarshal(body, &repoData); err != nil {\n\t\treturn \"\", fmt.Errorf(\"failed to parse GitHub API response: %w\", err)\n\t}\n\tif repoData.DefaultBranch == \"\" {\n\t\treturn \"\", fmt.Errorf(\"repository %s/%s has no default branch\", org, repo)\n\t}\n\treturn repoData.DefaultBranch, nil\n}\n\n// resolveGitHubSymlink checks if a file at the given path is a symlink/redirect to another file.\n// If the file contains a single line without newline, space, or colon then it's treated as a path to the actual file.\n// Returns a URL to the redirect path if found, or a URL for original path otherwise.\nfunc resolveGitHubSymlink(ctx context.Context, org, repo, branch, filePath, origBranch string) (string, error) {\n\tresp, err := getGitHubUserContent(ctx, org, repo, branch, filePath)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"failed to fetch file: %w\", err)\n\t}\n\tdefer resp.Body.Close()\n\n\t// Special rule for branch/tag propagation for github:ORG// requests.\n\tif resp.StatusCode == http.StatusNotFound && repo == org {\n\t\tdefaultBranch, err := getGitHubDefaultBranch(ctx, org, repo)\n\t\tif err == nil {","sourceCodeStart":126,"sourceCodeEnd":162,"githubUrl":"https://github.com/lima-vm/lima/blob/dd909d0973cd84fa35f9e1693181b4585ea616c1/pkg/limatmpl/github.go#L126-L162","documentation":"getGitHubDefaultBranch queries https://api.github.com/repos/ORG/REPO and unmarshals the default_branch field. When the API returns HTTP 200 but the default_branch field is empty or missing, Lima rejects the repository with \"repository ORG/REPO has no default branch\". This happens because the repo exists (or the API claims success) yet has no branch HEAD to resolve github: URLs against.","triggerScenarios":"Calling transformGitHubURL with a github:ORG/REPO... URL lacking an explicit @BRANCH, which triggers getGitHubDefaultBranch; the GitHub API returns 200 with an empty default_branch (e.g. an empty repository with no commits, or an API response shape that omits default_branch).","commonSituations":"Referencing a freshly created GitHub repo that has no commits yet; a repository where the default branch was deleted; a proxy or GitHub Enterprise mirror returning 200 with a stripped/empty JSON body; rate-limit or auth pages that happen to parse as JSON without default_branch.","solutions":["Verify the repository exists and has at least one commit so GitHub assigns a default branch","Pass an explicit branch in the URL (github:ORG/REPO@main) to skip the default-branch lookup entirely","Check the actual API response with `curl https://api.github.com/repos/ORG/REPO` to see what default_branch contains","If on GitHub Enterprise or behind a proxy, ensure the /repos/ORG/REPO endpoint returns the standard schema"],"exampleFix":"// before\nbranch, err := transformGitHubURL(ctx, \"github:empty-org/empty-repo\")\n// after\nbranch, err := transformGitHubURL(ctx, \"github:empty-org/empty-repo@main\")","handlingStrategy":"validation","validationCode":"resp, err := http.Get(\"https://api.github.com/repos/\" + org + \"/\" + repo)\nif err != nil { return err }\nvar meta struct{ DefaultBranch string `json:\"default_branch\"`; Size int `json:\"size\"` }\njson.NewDecoder(resp.Body).Decode(&meta)\nif resp.StatusCode != 200 || meta.DefaultBranch == \"\" || meta.Size == 0 {\n    return fmt.Errorf(\"repo %s/%s is empty or has no default branch; pass an explicit @branch\", org, repo)\n}","typeGuard":"func hasDefaultBranch(meta struct{ DefaultBranch string `json:\"default_branch\"` }) bool {\n    return meta.DefaultBranch != \"\"\n}","tryCatchPattern":"branch, err := transformGitHubURL(ctx, ref)\nvar hintErr error\nif err != nil && strings.Contains(err.Error(), \"has no default branch\") {\n    hintErr = fmt.Errorf(\"%w (hint: repository may be empty; specify github:ORG/REPO@BRANCH explicitly)\", err)\n}","preventionTips":["Only reference repositories with at least one commit","Pass an explicit @branch to skip the default-branch API lookup","Check repo metadata with `gh repo view ORG/REPO` before automating against it","Keep GH_TOKEN/GITHUB_TOKEN set so API responses are authentic and rate-limit free"],"tags":["github-api","http","network"],"backgroundTag":"github-default-branch-missing","analyzedSha":"dd909d0973cd84fa35f9e1693181b4585ea616c1","analyzedAt":"2026-09-01T14:24:59.842Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}