mislav/hub · error
Invalid GitHub URL: %s
Error message
Invalid GitHub URL: %s
What it means
NewProjectFromURL(url) splits url.Path into at most 4 segments and expects at least 3 ("", owner, name). If the path has 2 or fewer segments it cannot extract owner/name and returns this error. It guards against URLs that are hosts or bare root paths rather than repository URLs.
Source
Thrown at github/project.go:125
func NewProjectFromRepo(repo *Repository) (p *Project, err error) {
url, err := url.Parse(repo.HTMLURL)
if err != nil {
return
}
p, err = NewProjectFromURL(url)
return
}
func NewProjectFromURL(url *url.URL) (p *Project, err error) {
if !knownGitHubHostsInclude(url.Host) {
err = &HostError{url}
return
}
parts := strings.SplitN(url.Path, "/", 4)
if len(parts) <= 2 {
err = fmt.Errorf("Invalid GitHub URL: %s", url)
return
}
name := strings.TrimSuffix(parts[2], ".git")
p = newProject(parts[1], name, url.Host, url.Scheme)
return
}
func NewProject(owner, name, host string) *Project {
return newProject(owner, name, host, "")
}
func newProject(owner, name, host, protocol string) *Project {
if strings.Contains(owner, "/") {
result := strings.SplitN(owner, "/", 2)
owner = result[0]
if name == "" {View on GitHub (pinned to 5c547ed804)
Solutions
- Fix the remote URL to the full form host/owner/repo(.git): git remote set-url origin https://github.com/owner/repo.git
- Validate the URL shape before calling: URL.Path must contain /owner/name
- If a git config insteadOf rewrite is mangling the URL, correct `git config --get-regexp url`
- Re-enter the repository URL from `git remote -v` output to fix truncation
Example fix
// before git remote add origin https://github.com p, err := NewProjectFromURL(u) // Invalid GitHub URL // after git remote set-url origin https://github.com/owner/repo.git p, err := NewProjectFromURL(u) // OK
Defensive patterns
Strategy: validation
Validate before calling
func isRepoURL(raw string) bool {
u, err := url.Parse(raw)
if err != nil { return false }
parts := strings.SplitN(u.Path, "/", 4)
return len(parts) > 2 && parts[1] != "" && parts[2] != ""
} Try / catch
p, err := github.NewProjectFromURL(u)
if err != nil {
if strings.Contains(err.Error(), "Invalid GitHub URL") {
return nil, fmt.Errorf("URL %q lacks owner/name segments", u)
}
return nil, err
} Prevention
- Validate remote URLs contain /owner/name before use
- Never set a remote URL to just the host base
- Check git config url.<base>.insteadOf rules that rewrite paths to bare bases
- Copy full clone URLs (ending in owner/repo) rather than base URLs
When it happens
Trigger: Calling NewProjectFromURL with a URL whose path lacks owner/name, e.g. https://github.com, https://github.com/, or https://github.com/owner (called from findPushTarget, NewProjectFromRepo, Project, ParseURL when a remote URL is malformed or truncated).
Common situations: Remote URL set to just the host (e.g. git remote add origin https://github.com); truncated URL after a bad copy/paste; url.<base>.insteadOf rewrite producing a bare base URL; git:// or ssh URLs with empty path after parsing.
Related errors
- Aborted: could not find any git remote pointing to a GitHub
- could not find a git remote for '%s/%s'
- No valid remote URLs
- Repository '%s' already exists and is public
- Your access token may have insufficient scopes. Visit %s://%
AI-assisted analysis of mislav/hub@5c547ed804 (2026-09-01).
Data as JSON: /api/errors/a0d4ae8ff80adf49.
Report an issue: GitHub.