mislav/hub · error

No git remote with name %s

Error message

No git remote with name %s

What it means

RemoteByName(name) loads the repo's remotes and scans them for one whose name matches exactly. If none matches, it returns this error. The library throws it because publishing/upstream lookups require a specifically named remote that does not exist locally.

Source

Thrown at github/localrepo.go:52

		return err
	}
	r.remotes = remotes

	return nil
}

func (r *GitHubRepo) RemoteByName(name string) (*Remote, error) {
	if err := r.loadRemotes(); err != nil {
		return nil, err
	}

	for _, remote := range r.remotes {
		if remote.Name == name {
			return &remote, nil
		}
	}

	return nil, fmt.Errorf("No git remote with name %s", name)
}

func (r *GitHubRepo) remotesForPublish(owner string) (remotes []Remote) {
	r.loadRemotes()
	remotesMap := make(map[string]Remote)

	if owner != "" {
		for _, remote := range r.remotes {
			p, e := remote.Project()
			if e == nil && strings.EqualFold(p.Owner, owner) {
				remotesMap[remote.Name] = remote
			}
		}
	}

	names := OriginNamesInLookupOrder
	for _, name := range names {
		if _, ok := remotesMap[name]; ok {

View on GitHub (pinned to 5c547ed804)

Solutions

  1. Check `git remote -v` and use an existing remote name in the call/config
  2. Add the missing remote: git remote add origin <url>
  3. Rename an existing remote: git remote rename <old> <expected-name>
  4. If this is a fork setup, configure remote.<name>.fetch/push URLs for the expected remote

Example fix

// before
git remote add upstream git@github.com:org/repo.git
repo.RemoteByName("origin") // fails
// after
repo.RemoteByName("upstream") // matches configured remote
// or
// git remote rename upstream origin
Defensive patterns

Strategy: validation

Validate before calling

out, _ := exec.Command("git", "remote").Output()
remoteNames := strings.Fields(string(out))
hasOrigin := slices.Contains(remoteNames, "origin")
if !hasOrigin { /* add remote or use another name */ }

Try / catch

remote, err := repo.RemoteByName("origin")
if err != nil {
    if strings.HasPrefix(err.Error(), "No git remote with name") {
        return fmt.Errorf("configure remote 'origin': git remote add origin <url>")
    }
    return err
}

Prevention

When it happens

Trigger: Calling RemoteByName("origin") (or any name) via RemoteBranchAndProject, UpstreamProject, or remotesForPublish when `git remote -v` lists no remote with that exact name — typo, renamed remote, or no remotes configured at all.

Common situations: Remote renamed from 'origin' to a company convention (e.g. 'upstream', 'github'); fork workflows where only 'upstream'/'fork' exist; fresh clone with remotes removed; typo like 'originn'; multiple remotes where the requested one was deleted.

Related errors


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