Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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://user@server: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://user@server: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?

like image 546
Vince Avatar asked Mar 22 '23 07:03

Vince


2 Answers

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.

Edit:
The http-url stash gave me was user@server:7990/a/b/sandbox.git, while the ssh-url stash gave me is user@server: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.

like image 138
Vince Avatar answered Apr 01 '23 19:04

Vince


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.

like image 42
AD7six Avatar answered Apr 01 '23 19:04

AD7six