使用具有非标准端口的远程存储库

时间:2009-10-13 07:37:24

标签: git

我正在为远程存储库设置我的本地git项目。远程存储库在非标准端口(4019)上提供。

但它不起作用。相反,我收到以下错误消息:

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://root@git.host.de:4019/var/cache/git/project.git'

我的本​​地git配置是as follows

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

(端口和主机是实际端口和主机的占位符。)

我的git配置有什么问题?

5 个答案:

答案 0 :(得分:120)

基于SSH的git访问方法可以在<repo_path>/.git/config中使用完整URL或类似SCP的语法指定,如http://git-scm.com/docs/git-clone中所述:

网址格式:

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

SCP风格:

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

请注意,SCP样式不允许直接更改端口,而是依赖于ssh_config中的~/.ssh/config主机定义,例如:

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

然后你可以在shell中测试:

ssh my_git_host

并在<repo_path>/.git/config中将您SCP风格的URI更改为:

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

答案 1 :(得分:105)

如果你在.ssh/config

中添加了类似的内容
Host githost
HostName git.host.de
Port 4019
User root

然后您应该能够使用基本语法:

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

答案 2 :(得分:24)

试试这个

git clone ssh://user@32.242.111.21:11111/home/git/repo.git

答案 3 :(得分:9)

这可以避免您的问题,而不是直接修复它,但我建议您添加~/.ssh/config文件并使用此类文件

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

然后你可以

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

你也可以ssh git_hostscp git_host ...,一切都会成功。

答案 4 :(得分:7)

SSH在指定端口时不使用:语法。最简单的方法是编辑~/.ssh/config文件并添加:

Host git.host.de
  Port 4019

然后仅指定git.host.de没有端口号。