Git Reference ยท Revisions and Pathspecs
Git URLs
Reference for Git remote URLs: ssh://, https://, git://, file:// and the scp-like user@host:path form, local paths, ports, and rewriting with insteadOf.
A Git URL says where a repository lives and which transport to use. You meet them in git clone, git remote add, git fetch, git push, git submodule add and the url setting of a remote. Git chooses the transport from the prefix: ssh://, https://, git://, file://, or no scheme at all.
Two forms deserve special attention because they look different from ordinary URLs: the scp-like syntax user@host:path/to/repo.git (a colon, no scheme, no port) and plain local paths such as ../server.git. Git treats a string as scp-like only when there is no slash before the first colon.
git clone https://example.com/team/app.git git clone ssh://[email protected]:2222/team/app.git git clone [email protected]:team/app.git git clone ../server.git
Try it
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.
Syntax
ssh://[<user>@]<host>[:<port>]/<path>/<repo>.git git@<host>:<path>/<repo>.git (scp-like, no port) https://[<user>@]<host>[:<port>]/<path>/<repo>.git http://... (insecure; prefer https) git://<host>[:<port>]/<path>/<repo>.git (anonymous, read-only in practice) file:///<absolute-path>/<repo>.git /absolute/path or ../relative/path
| Form | Notes |
|---|---|
ssh:// |
Full URL; a port goes after the host. ~user paths work: ssh://host/~user/repo.git. |
| scp-like | Colon separates host from path. A relative path is relative to the remote user's home. There is no way to give a port; use ~/.ssh/config or ssh://. |
https:// |
Smart HTTP. Supports authentication with credential helpers and tokens. |
git:// |
The Git daemon protocol, port 9418. No authentication or encryption. |
file:// |
Goes through the real transport, like a remote would. |
| local path | Fastest: Git may hard-link objects when cloning. |
Errors and edge cases: fatal: '...' does not appear to be a git repository means the path or URL is wrong or not a repository. On Windows, C:/repo is a path, not a host named C, because a one-letter prefix is treated as a drive. Special characters in a user name or path must be percent-encoded in https:// URLs.
Usage notes
file://versus a plain path. A plain path may hard-link object files and skips the pack negotiation;file://behaves like a network clone, which matters for--depth(shallow clones are ignored on plain local paths) and for--filter. Usefile://when testing remote behavior.- scp-like syntax stops at the first slash.
./host:fileis a local path, whilehost:fileis remote; add./to force a local meaning for directories that contain a colon. - Relative submodule URLs such as
../lib.gitare resolved against the parent repository's remote; see .gitmodules. - Rewrites:
url.<base>.insteadOfreplaces a prefix for every operation, andurl.<base>.pushInsteadOfonly for pushes; see url.BASE.insteadOf. The longest matching prefix wins. - Allowed transports can be restricted with
protocol.allowandGIT_ALLOW_PROTOCOL; see protocol.*. Newer Git versions refusefilesubmodule clones by default. - Credentials in URLs (
https://user:password@host/...) end up in.git/configin plain text. Use a credential helper instead; see git credential. - Remote helpers: any other scheme
<name>://is handed to a program calledgit-remote-<name>; see Remote helpers. The form<transport>::<address>forces a specific helper. - Trailing
.gitis optional on most hosting services, because they redirect; on a plain file path or your own server it must match the directory name exactly.