git git远程添加其他SSH端口

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3596260/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 08:58:41  来源:igfitidea点击:

git remote add with other SSH port

gitsshport

提问by JuanPablo

In Git, how can I add a remote origin server when my host uses a different SSH port?

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

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

回答by igorw

You can just do this:

你可以这样做:

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

1234is the ssh port being used

1234是正在使用的 ssh 端口吗

回答by bramp

You need to edit your ~/.ssh/config file. Add something like the following:

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

Host example.com
    Port 1234

A quick google search shows a fewdifferentresources that explain it in more detail than me.

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

回答by kujiy

Best answer doesn't work for me. I needed ssh://from the beggining.

最佳答案对我不起作用。我ssh://从一开始就需要。

# does not work
git remote set-url origin [email protected]:10000/aaa/bbbb/ccc.git
# work
git remote set-url origin ssh://[email protected]:10000/aaa/bbbb/ccc.git

回答by Evan Carroll

For those of you editing the ./.git/config

对于那些编辑 ./.git/config

[remote "external"]                                                                                                                                                                                                                                                            
  url = ssh://[email protected]:11720/aaa/bbb/ccc                                                                                                                                                                                                               
  fetch = +refs/heads/*:refs/remotes/external/* 

回答by Konrad Rudolph

Rather than using the ssh://protocol prefix, you can continue using the?conventional URL form for accessing git over SSH, with one small change. As a reminder, the conventional URL is:

除了使用ssh://协议前缀,您可以继续使用传统的 URL 形式通过 SSH 访问 git,只需稍作改动。提醒一下,传统的 URL 是

git@host:path/to/repo.git

To specify an alternative port, put brackets around the user@hostpart, 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