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

  1. Add a remote: git remote add origin <repository-url>
  2. Verify with `git remote -v` that at least one remote exists
  3. In code, fall back to a default branch name when MainRemote() fails
  4. 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

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


AI-assisted analysis of mislav/hub@5c547ed804 (2026-09-01). Data as JSON: /api/errors/8ac58f1f1ba08fea. Report an issue: GitHub.