2010-08-29 114 views

回答

444

你可以只是這樣做:

git remote add origin ssh://[email protected]:1234/srv/git/example 

1234是正在使用

+7

Thx。只是一個補充:在路徑部分,使用絕對路徑,而不是用戶主目錄的相對路徑... – Snicolas 2012-05-28 19:54:21

+0

@Snicolas:爲什麼不應該使用相對路徑? – Hannes 2012-05-30 19:24:40

+16

因爲它不起作用。 – Snicolas 2012-05-30 20:10:59

103

您需要編輯您的〜/ .ssh/config文件SSH端口。添加像下面這樣:

Host example.com 
    Port 1234 

快速谷歌搜索顯示了fewdifferent資源解釋它比我更多的細節。

+0

這不起作用,它默認爲22. – jmoz 2012-07-03 16:55:00

+13

它確實爲我工作。我喜歡這種方法比把它放在git遙控器上更好。謝謝!無需通過這種方式指定絕對路徑。 – 2012-07-21 22:32:23

+0

這很好。同樣,我可以有一個特定的鍵,而不是默認的id_rsa。不僅如此,我的服務器是挑剔的,或多或少你必須迅速地擁有它,如果你包含密碼就會失敗。所以我也使用'PasswordAuthentication no'。 – 2014-01-08 01:33:28

-2

發現這個鏈接,雖然它是有幫助我的博客文章可能有助於澄清:

https://prestongarrison.com/change-port-git-is-using-for-ssh/

基本上我認爲它更好,只是編輯您的.git/config文件並進行更改。希望這會幫助別人..

+6

您是否可以將相關代碼添加到此帖子,而不是讓用戶點擊到外部網站? – iamnotmaynard 2015-12-22 15:43:02

10

對於那些編輯./.git/config

[remote "external"]                                                                
    url = ssh://[email protected]:11720/aaa/bbb/ccc                                                    
    fetch = +refs/heads/*:refs/remotes/external/* 
10

最佳答案對我不起作用。我需要從開始ssh://

# does not work 
git remote set-url origin [email protected]:10000/aaa/bbbb/ccc.git 
# work 
git remote set-url origin ssh://[email protected]:10000/aaa/bbbb/ccc.git