{"record":{"id":"8ac58f1f1ba08fea","repo":"mislav/hub","slug":"no-git-remotes-found","errorCode":null,"errorMessage":"no git remotes found","messagePattern":"no git remotes found","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"github/localrepo.go","lineNumber":245,"sourceCode":"\t\treturn nil, err\n\t}\n\n\tfor _, remote := range r.remotes {\n\t\tremoteProject, err := remote.Project()\n\t\tif err == nil && remoteProject.SameAs(project) {\n\t\t\treturn &remote, nil\n\t\t}\n\t}\n\treturn nil, fmt.Errorf(\"could not find a git remote for '%s'\", project)\n}\n\nfunc (r *GitHubRepo) MainRemote() (*Remote, error) {\n\tr.loadRemotes()\n\n\tif len(r.remotes) > 0 {\n\t\treturn &r.remotes[0], nil\n\t}\n\treturn nil, fmt.Errorf(\"no git remotes found\")\n}\n\nfunc (r *GitHubRepo) MainProject() (*Project, error) {\n\tr.loadRemotes()\n\n\tfor _, remote := range r.remotes {\n\t\tif project, err := remote.Project(); err == nil {\n\t\t\treturn project, nil\n\t\t}\n\t}\n\treturn nil, fmt.Errorf(\"Aborted: could not find any git remote pointing to a GitHub repository\")\n}\n\nfunc (r *GitHubRepo) CurrentProject() (project *Project, err error) {\n\tproject, err = r.UpstreamProject()\n\tif err != nil {\n\t\tproject, err = r.MainProject()\n\t}","sourceCodeStart":227,"sourceCodeEnd":263,"githubUrl":"https://github.com/mislav/hub/blob/5c547ed804368763064e51f3990851e267e88edd/github/localrepo.go#L227-L263","documentation":"MainRemote() returns the first loaded remote (by git's remote ordering) as the 'main' remote. If the repository has zero remotes after loading, it returns this error. MasterBranch depends on it, so branch discovery fails without any remote.","triggerScenarios":"Calling MainRemote() (directly or via MasterBranch) on a repo where `git remote` output is empty: a locally `git init`-ed repo, remotes removed with `git remote remove`, or Remotes() parsing produced an empty list.","commonSituations":"Fresh git init before adding origin; cloned tarballs/zips without git history; sandbox/CI environments that strip remotes; repos where all remotes were deleted during cleanup.","solutions":["Add a remote: git remote add origin <repository-url>","Verify with `git remote -v` that at least one remote exists","In code, fall back to a default branch name when MainRemote() fails","Re-clone properly if the checkout was created without git metadata"],"exampleFix":"// before\ngit init\nbranch := repo.MasterBranch() // panics: no git remotes found\n// after\ngit remote add origin https://github.com/org/repo.git\nbranch := repo.MasterBranch()","handlingStrategy":"fallback","validationCode":"out, err := exec.Command(\"git\", \"remote\").Output()\nif err != nil || len(strings.Fields(string(out))) == 0 {\n    // no remotes configured; add one or skip remote-dependent logic\n}","typeGuard":null,"tryCatchPattern":"remote, err := repo.MainRemote()\nif err != nil {\n    if err.Error() == \"no git remotes found\" {\n        return nil, fmt.Errorf(\"add a remote first: git remote add origin <url>\")\n    }\n    return nil, err\n}","preventionTips":["Add origin right after `git init` as part of project bootstrap","Check `git remote` non-empty before remote-dependent calls","Avoid stripping remotes in CI/cleanup steps that later run hub commands","Clone with git rather than downloading archives to keep remotes intact"],"tags":["git","remote-configuration","setup"],"backgroundTag":"no-git-remote-configured","analyzedSha":"5c547ed804368763064e51f3990851e267e88edd","analyzedAt":"2026-09-01T03:34:15.525Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}