在Git中,当主机使用不同的SSH端口时,如何添加远程源服务器?
git remote add origin ssh://user@host/srv/git/example
答案 0 :(得分:521)
你可以这样做:
git remote add origin ssh://user@host:1234/srv/git/example
1234
是正在使用的ssh端口
答案 1 :(得分:120)
答案 2 :(得分:22)
最佳答案对我不起作用。我需要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
答案 3 :(得分:14)
对于那些编辑./.git/config
[remote "external"]
url = ssh://evanc@www.foo.com:11720/aaa/bbb/ccc
fetch = +refs/heads/*:refs/remotes/external/*
答案 4 :(得分:2)
除了使用ssh://
协议前缀之外,您还可以继续使用传统的URL形式通过SSH访问git,但有一个小的更改。提醒您,the conventional URL is:
git@host:path/to/repo.git
要指定备用端口,请在user@host
部分周围放置括号,包括端口:
[git@host:port]:path/to/repo.git
但是,如果端口更改只是临时的,则可以告诉git使用其他SSH命令,而不是更改存储库的远程URL:
export SSH_GIT_COMMAND='ssh -p port'
git clone git@host:path/to/repo.git # for instance
答案 5 :(得分:0)
对于 gitlab,示例 ssh 端口是 2224,因此:
<块引用>git 远程添加 ssh://git@192.168.1.100:2224/your_group/your_project.git
答案 6 :(得分:-1)
1.git remote add ${shortname} ${url}
2.git remote remove 短名(是删除远程)
3.git remote -v(就是查看你当前的远程列表)
4.git push 远程分支
5.git remote rename A B (rename A to B)
6.git remote show shortname(显示远程信息)
所有这些都对我有用。