Shorter Git URLs
At our office, we started off with the simplest possible way of sharing Git repositories (well, apart from using Github): Bare repositories on a server with SSH access.
So, our first Git URL looked like this:
ssh://git@git.ourservers.com/var/git/foo.git
However, it quickly became obvious that the above URL schema has a shorthand format (if ~git = /var/git):
git@git.ourservers.com:foo.git
We can also leave out the .git suffix in the end, as Git will append this for us automatically.
Now, if we were to configure our ~/.ssh/config with an alias and a username for this SSH connection:
Host git
HostName git.ourservers.com
User git
Now we can use the alias host, and leave out the username. So now, when we want to clone a repository "foo", we just do:
git clone git:foo
The same principle can be used for any SSH/Git server, including Github.
Say I have the SSH URL from the Github web interface:
git@github.com:tfnico/guava-examples.git
I add an ~/.ssh/config entry like this:
Host hub
HostName github.com
User git
Now I can do this locally:
git clone hub:tfnico/guava-examples
It even works on Windows with OpenSSH (or Github for Windows).
Written by Thomas Ferris Nicolaisen
Related protips
2 Responses
For GitHub you can also install hub
and use only git clone name/repo
Or you can add an alias in your ~/.gitconfig:
[url "https://github.com/"]
insteadOf = gh://
and execute:
git clone gh://knoopx/repo