cloning git-repository from stash via ssh

cloning git-repository from stash via ssh

I’ve got a git-repository running on a stash-server. Cloning the repository via http works fine

git clone http://[email protected]:7990/a/b/sandbox.git

For some weird reason, when I switch http with ssh and with it the port, it gives me

git clone ssh://[email protected]:7999/a/b/sandbox.git
Cloning into sandbox...
fatal: remote error: Remote URL invalid
A repository could not be determined from the remote URL. Please confirm the
clone URL in Stash and try again. URL suffix: '/scm/ct/sandbox.git'
fatal: The remote end hung up unexpectedly

The server has ssh enabled and the port set to 7999. How comes, that it can’t find the repository when the request is sent via ssh rather than http?

Problem solved. For some reason, the SSH-URL-suffix for the repository is different from the HTTP-URL-suffix. After finding that out, it worked.

The http-url stash gave me was [email protected]:7990/a/b/sandbox.git, while the ssh-url stash gave me is [email protected]:7999/b/sandbox.git (where a and b are of course placeholders).

As it was mentioned in the comments, that I should add this to my answer.

Configure ssh to do it for you

Unless it’s desirable to write out explicitly the clone url (e.g. cloning is performed by a parameterized script) it’s generally easier to configure ssh so that it understands what server means and therefore the command arguments are just the defaults you’d normally expect. So for example in your ssh config file put:

Host server
  User user
  Port 7999

Which then permits:

$ git clone server:/a/b/sandbox.git

In this way, and especially if there are multiple repositories on the git server, it means you don´t need to remember the more complex/explicit syntax to clone a repo.