17

Please pardon my ignorance; I'm new to Git and not sure where better to look for an answer, but what's the purpose of the colon after 'example.com' in the following url (which points to a git repository on my mediatemple server)?

git remote add repo_name ssh://serveradmin%[email protected]:/home/45678/domains/git.example.com/html/example.git

5
  • 2
    Looks like a meaningless colon. Normally the port number would follow, but without a number, the default port number for ssh (22) should be used.
    – harpo
    Commented Mar 11, 2011 at 23:52
  • You think like I think but it's not meaningless, there are colons in many of these git URL paths and I copied this straight from the mediatemple documentation. It's doing something different than the usual port number indicator thing, I think. Let me know if I am wrong. Commented Mar 12, 2011 at 0:55
  • 2
    I love URLs that aren't — it's obviously invalid because "%ex" isn't a valid percent-escape. The bit where they use :// but don't follow the generic syntax is merely a minor annoyance, and probably stems from the ssh user@host:path syntax (where path is absolute or relative to your home dir).
    – tc.
    Commented Mar 12, 2011 at 4:04
  • Are you sure % is not valid? I've used two hosts that used % instead of @ in their login instructions. Commented Mar 13, 2011 at 6:46
  • And you may have hit on the answer: is 'ssh user@host:path' standard ssh syntax? Other commmenators have suggested this, that it is specifically ssh syntax. I will look for documentation to see whether this is the case. Commented Mar 13, 2011 at 7:13

3 Answers 3

12

This syntax is actually wrong, but it's a bit like the scp-style syntax that you can use in git URLs, where it separates the hostname from the path on that host. Your options for specifying git URLs are listed in the git clone documentation. In your case you probably want one of the following instead:

 serveradmin%[email protected]:/home/45678/domains/git.example.com/html/example.git

... or:

 ssh://serveradmin%[email protected]/home/45678/domains/git.example.com/html/example.git

In either case, the username is serveradmin%example.com, the hostname is example.com and the path on that host is /home/45678/domains/git.example.com/html/example.git.

3
  • Wait, where exactly is the syntax wrong? Your first example looks just like the one I posted. Feel free to assume I know nothing. And tell me more about this "scp-style syntax that you can use in git URLs" -- I don't know what that is. If you can point me to documentation, that helps. When I intitally asked the question about these colons I though it had something to do wth git-specific or ssh-specific syntax; I think I might have been right, but so far there hasn't been a definitive answer. (I appreciate all the answers, whatever the case.) Commented Mar 13, 2011 at 6:54
  • 2
    My first example doesn't have the ssh:// at the start, whereas your one does. You're only allowed the : in the version without the ssh://. The only documentation about what URLs you can use to refer to git repositories is in the git clone man page that I've linked to in my answer. scp is a command line tool for copying files over SSH that happens to require you to specify the location of files on remote systems as user@host:filename. Since scp is widely used and familiar to people, git allows you to use it to specify the repository as well as the strict URL version. Commented Mar 13, 2011 at 8:11
  • Thanks for clarifying. I had never used scp before using git, so it wasn't familiar to me; I appreciate your explanation. I'm accepting this as the answer. Commented Mar 13, 2011 at 17:28
4

It separates the hostname (of the server)from the path (to the repo) as explained here

3
  • thanks for the link. It may raise more questions (for me) than it solves. If the colon is part of a URI scheme, and a URI scheme, as described in the link is made of: <scheme name> : <hierarchical part> [ ? <query> ] [ # <fragment> ] then where is the scheme name? I thought ssh: might be the scheme name here. Normally a hostname is separated from a path by a slash, right? I'm accustomed to seeing a colon preceding a port number, as @harpo mentions above, but a free-standing colon is new to me. You're telling me it is not a git thing but a standard element of a URI? Commented Mar 12, 2011 at 0:40
  • Looking at the git-clone man page it appears it may actually be an scp-like syntax which is supported by git kernel.org/pub/software/scm/git/docs/git-clone.html
    – objects
    Commented Mar 12, 2011 at 7:11
  • 1
    I think your answer might be correct, but your explanation (linking to a page that covers a lot of information about URIs in general) is more confusing than helpful. Commented Mar 13, 2011 at 6:48
0

The colon is notation which indicates to git the string after defines the repository you wish to interact with.

edit: Well spotted

As we can see the remote add is as follows:

git remote add [-t <branch>] [-m <master>] [-f] [--tags|--no-tags] [--mirror] <name> <url>

and your example is:

git remote add repo_name ssh://serveradmin%[email protected]:/home/45678/domains/git.example.com/html/example.git

where 'name' is 'repo_name'

and URL is the big string

ssh://serveradmin%[email protected]:/home/45678/domains/git.example.com/html/example.git

which is even more apparent when we see it has the ssh protocol definition at the beginning.

In a URL you can define the colon without the proceeding port value and the default port for that protocol is generally used as the port number which seems to be what is happening here.

Therefore markup for the question and mark up for harpo's comment

1
  • I think this might be the answer, but what does it mean if there is no string? Commented Mar 12, 2011 at 0:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.