在Git中,当我的主机使用不同的SSH端口时,如何添加远程源服务器?

git remote add origin ssh://user@host/srv/git/example

当前回答

你可以这样做:

git remote add origin ssh://user@host:1234/srv/git/example

1234为正在使用的SSH端口

其他回答

你可以这样做:

git remote add origin ssh://user@host:1234/srv/git/example

1234为正在使用的SSH端口

您需要编辑~/。ssh / config文件。添加如下内容:

Host example.com
    Port 1234

快速搜索谷歌会显示一些不同的资源,它们比我更详细地解释了它。

对于那些编辑。/.git/config的人

[remote "external"]                                                                                                                                                                                                                                                            
  url = ssh://evanc@www.foo.com:11720/aaa/bbb/ccc                                                                                                                                                                                                               
  fetch = +refs/heads/*:refs/remotes/external/* 

最好的答案对我没用。我需要ssh://从乞求。

# does not work
git remote set-url origin user@example.com:10000/aaa/bbbb/ccc.git
# work
git remote set-url origin ssh://user@example.com:10000/aaa/bbbb/ccc.git

您可以继续使用传统的URL形式通过ssh访问git,而不是使用ssh://协议前缀,只是做了一个小更改。提醒一下,常规的URL是:

git@host:path/to/repo.git

要指定一个替代端口,在user@host部分周围加上括号,包括端口:

[git@host:port]:path/to/repo.git

但是如果端口更改只是暂时的,你可以告诉git使用不同的SSH命令,而不是更改存储库的远程URL:

export GIT_SSH_COMMAND='ssh -p port'
git clone git@host:path/to/repo.git # for instance