Using a remote repository with non-standard port

Git

Git Problem Overview


I am setting up my local git project for a remote repository. The remote repository is being served on a non-standard port (4019).

But it doesn't work. Instead I get the following error message:

ssh: connect to host git.host.de:4019 port 22: Connection refused
fatal: The remote end hung up unexpectedly
error: failed to push to 'ssh://[email protected]:4019/var/cache/git/project.git'

My local git config is as follows:

[core]
  repositoryformatversion = 0
  filemode = true
  bare = false
  logallrefupdates = true
[remote "origin"]
  url = ssh://[email protected]:4019/var/cache/git/project.git
  fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
  remote = origin
  merge = refs/heads/master

(The port and host are placeholders for the actual port and host.)

What is wrong with my git configuration?

Git Solutions


Solution 1 - Git

SSH based git access method can be specified in <repo_path>/.git/config using either a full URL or an SCP-like syntax, as specified in http://git-scm.com/docs/git-clone:

URL style:

url = ssh://[user@]host.xz[:port]/path/to/repo.git/

SCP style:

url = [user@]host.xz:path/to/repo.git/

Notice that the SCP style does not allow a direct port change, relying instead on an ssh_config host definition in your ~/.ssh/config such as:

Host my_git_host
HostName git.some.host.org
Port 24589
User not_a_root_user

Then you can test in a shell with:

ssh my_git_host

and alter your SCP-style URI in <repo_path>/.git/config as:

url = my_git_host:path/to/repo.git/

Solution 2 - Git

If you put something like this in your .ssh/config:

Host githost
HostName git.host.de
Port 4019
User root

then you should be able to use the basic syntax:

git push githost:/var/cache/git/project.git master

Solution 3 - Git

Try this

git clone ssh://[email protected]:11111/home/git/repo.git

Solution 4 - Git

This avoids your problem rather than fixing it directly, but I'd recommend adding a ~/.ssh/config file and having something like this

Host git_host
HostName git.host.de
User root
Port 4019

then you can have

url = git_host:/var/cache/git/project.git

and you can also ssh git_host and scp git_host ... and everything will work out.

Solution 5 - Git

SSH doesn't use the : syntax when specifying a port. The easiest way to do this is to edit your ~/.ssh/config file and add:

Host git.host.de
Port 4019

Then specify just git.host.de without a port number.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionbrainfckView Question on Stackoverflow
Solution 1 - GitjdpfView Answer on Stackoverflow
Solution 2 - GitCB BaileyView Answer on Stackoverflow
Solution 3 - GitRicky SahuView Answer on Stackoverflow
Solution 4 - GitPeterView Answer on Stackoverflow
Solution 5 - GitGreg HewgillView Answer on Stackoverflow