git remote添加其他SSH端口

本文翻译自: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
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值