git remote add with other SSH port

2019-01-07 02:25发布

问题:

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

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

回答1:

You can just do this:

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

1234 is the ssh port being used



回答2:

You need to edit your ~/.ssh/config file. 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.



回答3:

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

# 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


回答4:

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

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


标签: git ssh port