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

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

当前回答

最好的答案对我没用。我需要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

其他回答

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

Host example.com
    Port 1234

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

您可以继续使用传统的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

看看如何设置你的~/。Ssh /config文件正确。

您可以轻松地为不同的主机指定不同的设置。

来解决你的问题

Host github.com 
Port 22 
Host * 
Port 1234

看一下ssh_config手册页,它解释了前几页需要了解的所有内容。

1.Git远程添加${shortname} ${url}

2.Git远程删除短名称(是删除远程)

3.Git remote -v(查看当前远程列表)

4.Git推送远程分支

5.git远程重命名A B(重命名A到B)

6.Git远程显示shortname(显示远程信息)

这一切都对我有用。

最好的答案对我没用。我需要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