2011-09-07 115 views
11

克隆由gitolite一個管理的倉庫通常採用以下語法gitolite使用非默認端口

git clone [email protected]:repository 

這告訴SSH客戶端連接到端口22使用gitolite用戶名服務器的。當我嘗試它的端口號:

git clone [email protected]:22:repository 

Git的抱怨庫22:庫不可用。如果SSH服務器使用不同的端口,應該使用什麼語法?

+0

[git remote add with other ssh port]可能重複(http://stackoverflow.com/questions/3596260/git-remote-add-with-other-ssh-port) –

回答

17

「SCP style」Git URL語法([email protected]:path)不支持包含端口。要包含端口,您必須使用ssh://「Git URL」。例如:

ssh://[email protected]:2222/repository 

注:相比於[email protected]:repository,這提出了一個稍微不同的存儲庫路徑到遠端(絕對/repository代替相對路徑repository); Gitolite接受這兩種類型的路徑,其他系統可能會有所不同。


另一種方法是在使用Host進入你的~/.ssh/config(請參閱您ssh_config(5) manpage)。使用這樣的條目,您可以創建一個包含服務器名稱/地址,遠程用戶名和非默認端口號(以及任何其他可能的SSH選項)的「SSH主機暱稱」:

Host gitolite 
    User  gitolite 
    HostName server 
    Port  2222 

然後,您可以使用非常簡單的Git URL,如gitolite:repository


如果你有記錄(和或配置)這多個人,我會ssh://網址去,因爲不涉及額外的配置。

如果這僅適用於您(特別是如果您最終可能從同一臺服務器訪問多個存儲庫),那麼使用SSH主機暱稱可以節省一些打字可能會更好。

2

它在這裏非常詳細的解釋:https://github.com/sitaramc/gitolite/blob/pu/doc/ssh-troubleshooting.mkd#_appendix_4_host_aliases

使用在〜/ .ssh /配置「主機」對讓你很好地封裝了所有這一切SSH內,並給它一個簡短,易記,名稱。例如:

host gitolite 
    user git 
    hostname a.long.server.name.or.annoying.IP.address 
    port 22 
    identityfile ~/.ssh/id_rsa 

現在,你可以簡單地用一個詞gitolite(這是我們在這裏所定義的主機別名)和ssh會推斷出所有那些在它定義的細節 - 只是說SSH gitolite和git克隆gitolite:reponame事情會起作用。