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

bra*_*fck 121 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'
Run Code Online (Sandbox Code Playgroud)

我的本地git配置如下:

[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
Run Code Online (Sandbox Code Playgroud)

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

我的git配置有什么问题?

小智 123

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

网址样式:

url = ssh://[user@]host.xz[:port]/path/to/repo.git/
Run Code Online (Sandbox Code Playgroud)

SCP风格:

url = [user@]host.xz:path/to/repo.git/
Run Code Online (Sandbox Code Playgroud)

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

Host my_git_host
HostName git.some.host.org
Port 24589
User not_a_root_user
Run Code Online (Sandbox Code Playgroud)

然后你可以在shell中测试:

ssh my_git_host
Run Code Online (Sandbox Code Playgroud)

并改变你的SCP式URI <repo_path>/.git/config:

url = my_git_host:path/to/repo.git/
Run Code Online (Sandbox Code Playgroud)


CB *_*ley 112

如果你把这样的东西放在你的.ssh/config:

Host githost
HostName git.host.de
Port 4019
User root
Run Code Online (Sandbox Code Playgroud)

那么你应该能够使用基本语法:

git push githost:/var/cache/git/project.git master
Run Code Online (Sandbox Code Playgroud)

  • 注意任何仍然需要这个的人.语法为`git clone ssh:// username @ hostname:333 /〜/ repo`,表示相对于主目录的路径,或者`git clone ssh:// username @ hostname:333/path/to/repo`表示绝对路径 (33认同)
  • SSH配置可能是一种解决方法,但这让我感兴趣,因为man git-push说接受的ssh url格式是ssh:// [user @] host.xz [:port] /path/to/repo.git / (4认同)

Ric*_*cky 26

试试这个

git clone ssh://user@32.242.111.21:11111/home/git/repo.git
Run Code Online (Sandbox Code Playgroud)


Pet*_*ter 9

这可以避免您的问题,而不是直接修复它,但我建议添加一个~/.ssh/config文件,并有类似的东西

Host git_host
HostName git.host.de
User root
Port 4019
Run Code Online (Sandbox Code Playgroud)

那么你可以拥有

url = git_host:/var/cache/git/project.git
Run Code Online (Sandbox Code Playgroud)

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


Gre*_*ill 7

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

Host git.host.de
  Port 4019

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