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
- If privacy is required, change visibility in GitHub Settings (General -> Danger Zone -> Change visibility) or via API, then continue.
- Delete the existing public repo (if safe) and rerun `hub create -p`.
- Choose a different repository name that doesn't exist.
- 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
- Probe the API for the repo's existence/visibility before create scripts run
- Use unique repo names (timestamp/suffix) in automation
- Decide public vs private up front and don't flip with -p on retries
- Rerun without -p if reusing the existing repo is acceptable
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
- 'create' must be run from inside a git repository
- Error: couldn't detect shell type. Please specify your shell
- hub alias: unsupported shell supported shells: %s
- Unsupported flag -b when checking out pull request
- Unsupported flag --orphan when checking out pull request
AI-assisted analysis of mislav/hub@5c547ed804 (2026-09-01).
Data as JSON: /api/errors/627c3fdb0241004b.
Report an issue: GitHub.