Skip to content

parseGitRemoteUrl

parseGitRemoteUrl(url): GitRemote | undefined

Defined in: remote.ts:38

Parses a git remote URL — any host, any of the common shapes:

  • https://github.com/owner/repo(.git)(/), with optional credentials or port
  • git@github.com:owner/repo(.git) (scp-style SSH)
  • ssh://git@github.com(:22)/owner/repo(.git)
  • git://github.com/owner/repo.git

A bracketed IPv6 host is returned without its brackets. The whole input must be one remote: trailing text after the URL (apart from a ?query or #fragment) makes it undefined.

undefined for anything else (a local path, an empty string, a URL with fewer than two path segments). Nested groups stay in owner.

string

GitRemote | undefined

import { parseGitRemoteUrl } from "@theholocron/git-utils";
parseGitRemoteUrl("git@github.com:theholocron/holocron.git");
// { host: "github.com", owner: "theholocron", repo: "holocron", slug: "theholocron/holocron" }
parseGitRemoteUrl("/Users/me/code/repo"); // undefined