本文翻译自:git remote add with other SSH port
在Git中,当主机使用不同的SSH端口时,如何添加远程源服务器?
git remote add origin ssh://user@host/srv/git/example
#1楼
参考:https://stackoom.com/question/F5YC/git-remote添加其他SSH端口
#2楼
For those of you editing the ./.git/config
对于那些编辑./.git/config
[remote "external"]
url = ssh://evanc@www.foo.com:11720/aaa/bbb/ccc
fetch = +refs/heads/*:refs/remotes/external/*
#3楼
You can just do this: 你可以这样做:
git remote add origin ssh://user@host:1234/srv/git/example
1234
is the ssh port being used 1234
是正在使用的ssh端口
#4楼
You need to edit your ~/.ssh/config file. 您需要编辑〜/ .ssh / config文件。 Add something like the following: 添加如下内容:
Host example.com
Port 1234
A quick google search shows a few different resources that explain it in more detail than me. 快速谷歌搜索显示了一些 不同的资源,比我更详细地解释它。
#5楼
Best answer doesn't work for me. 最佳答案对我不起作用。 I needed ssh://
from the beggining. 我需要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
#6楼
Rather than using the ssh://
protocol prefix, you can continue using the conventional URL form for accessing git over SSH, with one small change. 您可以继续使用传统的URL表单通过SSH访问git,而不是使用ssh://
协议前缀,只需稍作修改即可。 As a reminder, the conventional URL is : 提醒一下,传统的URL是 :
git@host:path/to/repo.git
To specify an alternative port, put brackets around the user@host
part, including the port: 要指定备用端口,请在user@host
部分周围放置括号,包括端口:
[git@host:port]:path/to/repo.git
But if the port change is merely temporary, you can tell git to use a different SSH command instead of changing your repository's remote URL: 但是如果端口更改只是暂时的,您可以告诉git使用不同的SSH命令而不是更改存储库的远程URL:
export SSH_GIT_COMMAND='ssh -p port'
git clone git@host:path/to/repo.git # for instance