vznqwq
Last Updated: July 27, 2016
·
2.864K
· tfnico
C62aa573cdb3cecd291e96b9771844b1

Shorter Git URLs

git

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).

Say Thanks
Respond

2 Responses
Add your response

1811
Me

For GitHub you can also install hub and use only git clone name/repo

over 1 year ago ·
13247
Ecc4d502278ae77354564beb97bdff10

Or you can add an alias in your ~/.gitconfig:

[url "https://github.com/"]
  insteadOf = gh://

and execute:

git clone gh://knoopx/repo
over 1 year ago ·
Filed Under