mislav/hub · error

Repository '%s' already exists and is public

Error message

Repository '%s' already exists and is public

What it means

In commands/create.go create, when gh.Repository(project) succeeds the repo already exists on the host. If it is the same project and is public while the user requested a private repo (flagCreatePrivate), the command fails with "Repository '%s' already exists and is public" because privacy cannot be retroactively applied this way.

Source

Thrown at commands/create.go:105

	owner := host.User
	if strings.Contains(newRepoName, "/") {
		split := strings.SplitN(newRepoName, "/", 2)
		owner = split[0]
		newRepoName = split[1]
	}

	project := github.NewProject(owner, newRepoName, host.Host)
	gh := github.NewClient(project.Host)

	flagCreatePrivate := args.Flag.Bool("--private")

	repo, err := gh.Repository(project)
	if err == nil {
		foundProject := github.NewProject(repo.FullName, "", project.Host)
		if foundProject.SameAs(project) {
			if !repo.Private && flagCreatePrivate {
				err = fmt.Errorf("Repository '%s' already exists and is public", repo.FullName)
				utils.Check(err)
			} else {
				ui.Errorln("Existing repository detected")
				project = foundProject
			}
		} else {
			repo = nil
		}
	} else {
		repo = nil
	}

	if repo == nil {
		if !args.Noop {
			flagCreateDescription := args.Flag.Value("--description")
			flagCreateHomepage := args.Flag.Value("--homepage")
			repo, err := gh.CreateRepository(project, flagCreateDescription, flagCreateHomepage, flagCreatePrivate)
			utils.Check(err)

View on GitHub (pinned to 5c547ed804)

Solutions

  1. If privacy is required, change visibility in GitHub Settings (General -> Danger Zone -> Change visibility) or via API, then continue.
  2. Delete the existing public repo (if safe) and rerun `hub create -p`.
  3. Choose a different repository name that doesn't exist.
  4. If the existing public repo is fine, rerun without `-p` and let hub reuse it (it prints "Existing repository detected").

Example fix

// before
hub create -p   // Repository 'user/proj' already exists and is public
// after
# either reuse it:
hub create
# or flip visibility first via GitHub settings, then:
hub create -p
Defensive patterns

Strategy: validation

Validate before calling

// check existing repo visibility before requesting private create
repo, err := gh.Repository(project)
if err == nil && !repo.Private && flagCreatePrivate {
    return fmt.Errorf("%s exists and is public; change visibility or pick another name", repo.FullName)
}

Try / catch

repo, err := gh.Repository(project)
if err == nil {
    if !repo.Private && flagCreatePrivate {
        fmt.Fprintln(os.Stderr, "repo exists as public; adjusting visibility via API")
        // handle: change visibility or choose new name
    }
}

Prevention

When it happens

Trigger: Running `hub create -p` (private) for a repository name that already exists on the host as a public repo whose FullName maps to the same project (foundProject.SameAs(project)).

Common situations: Re-running `hub create -p` after an earlier public create; name collision with an existing public repo under your account/org; scripted create that assumed fresh names; switching from public to private expectations mid-setup.

Related errors


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