Search code examples
giturlsshatlassian-sourcetreesourcetree

Clone SSH repository with non-standard port number to SourceTree


I spent about 20 minutes messing around with this problem.

I was emailed an SSH address for a repository. Crucially it had a non-standard (i.e. not 22) port number: git@domain.com:1234/opt/git/repository.git

I assumed I could just copy-paste that into SourceTree, but kept getting This is not a valid source path / URL error messages.

When I took a closer look at the logs, the error was that it was looking for the path 1234/opt/git/repository.git on the server - it was treating the port number as part of the path. And obviously not finding the repo.


Solution

  • The solution was slightly weird:

    1. Use a path like ssh://git@domain.com:1234:/opt/git/repository.git. Appending ssh://, and adding a : after the port number seemed to successfully act as a delimiter, and the path /opt/git/repository.git was found (as expected) on the server.
    2. Add the domain/port number to your config file (e.g. ~/.ssh/config) so that it looks like this:

    Host domain.com Port 1234