mislav/hub · error
no git remotes found
Error message
no git remotes found
What it means
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.
Source
Thrown at github/localrepo.go:245
return nil, err
}
for _, remote := range r.remotes {
remoteProject, err := remote.Project()
if err == nil && remoteProject.SameAs(project) {
return &remote, nil
}
}
return nil, fmt.Errorf("could not find a git remote for '%s'", project)
}
func (r *GitHubRepo) MainRemote() (*Remote, error) {
r.loadRemotes()
if len(r.remotes) > 0 {
return &r.remotes[0], nil
}
return nil, fmt.Errorf("no git remotes found")
}
func (r *GitHubRepo) MainProject() (*Project, error) {
r.loadRemotes()
for _, remote := range r.remotes {
if project, err := remote.Project(); err == nil {
return project, nil
}
}
return nil, fmt.Errorf("Aborted: could not find any git remote pointing to a GitHub repository")
}
func (r *GitHubRepo) CurrentProject() (project *Project, err error) {
project, err = r.UpstreamProject()
if err != nil {
project, err = r.MainProject()
}View on GitHub (pinned to 5c547ed804)
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
Example fix
// before git init branch := repo.MasterBranch() // panics: no git remotes found // after git remote add origin https://github.com/org/repo.git branch := repo.MasterBranch()
Defensive patterns
Strategy: fallback
Validate before calling
out, err := exec.Command("git", "remote").Output()
if err != nil || len(strings.Fields(string(out))) == 0 {
// no remotes configured; add one or skip remote-dependent logic
} Try / catch
remote, err := repo.MainRemote()
if err != nil {
if err.Error() == "no git remotes found" {
return nil, fmt.Errorf("add a remote first: git remote add origin <url>")
}
return nil, err
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- No git remote with name %s
- could not find a git remote for '%s/%s'
- could not find a git remote for '%s'
- Aborted: could not find any git remote pointing to a GitHub
- No valid remote URLs
AI-assisted analysis of mislav/hub@5c547ed804 (2026-09-01).
Data as JSON: /api/errors/8ac58f1f1ba08fea.
Report an issue: GitHub.