Identifiers

Git Remote URL (HTTPS or SSH)

Match git remote URLs in both `git@host:org/repo` and `https://host/org/repo` forms.

Try it in RegexPro →

Available in

Pattern

regexengine-agnostic
(?:git@|https?:\/\/)([\w.\-]+)[:\/]([\w.\-]+)\/([\w.\-]+?)(?:\.git)?\/?$

Raw source: (?:git@|https?:\/\/)([\w.\-]+)[:\/]([\w.\-]+)\/([\w.\-]+?)(?:\.git)?\/?$

How it works

(?:git@|https?:\/\/) matches either the SSH `git@` prefix or HTTP/HTTPS scheme. ([\w.\-]+) captures the host. [:\/] matches the host/path separator (colon for SSH, slash for HTTPS). The next two groups capture org and repo. (?:\.git)? optionally strips the trailing `.git`. \/? allows a trailing slash.

Examples

Input

git@github.com:vercel/next.js.git

Matches

  • git@github.com:vercel/next.js.git

Input

https://gitlab.com/group/subproject

Matches

  • https://gitlab.com/group/subproject

Input

not a git url

No match

Common use cases

  • .gitmodules / submodule resolution
  • Migration scripts between hosts
  • CI tooling that ingests repo URLs
  • Dependency-source resolution (Go modules, npm git deps)