2017-03-16 135 views
0

我在通過git訪問Gerrit上的外部存儲庫時遇到了問題。 當我嘗試蠢貨,克隆庫目錄獲取(克隆效果很好),我得到:git fetch in repo dir'Permission denied',but working with direct link with user

> git fetch 
Permission denied (publickey). 
fatal: Could not read from remote repository. 

Please make sure you have the correct access rights 
and the repository exists. 

但是,當我直接與倉庫SSH地址和用戶名做,我得到:

> git fetch ssh://[email protected]:port/repo_name 
remote: Counting objects: xxxx, done 
remote: Finding sources: 100% (xxx/xxx) 
etc... 

所以直接git fetch似乎運作良好。 我試着設置不同的用戶名:

git config --global user.name "username" 

,但沒有用 - 我仍然得到權限被拒絕(公鑰)。 再次 - git克隆工作正常。

任何想法如何解決這個問題?

回答

0

弗里斯特,檢查用於獲取當前URL:

git remote show origin

然後,如果提取網址不匹配,使用以下命令將其更改:

git remote set-url origin ssh://[email protected]:port/repo_name

+0

謝謝!這爲我修好了。原始URL具有不同的用戶,因此我已將每個repo /.git/config文件中的值更改爲我的用戶名。 –

0

的Git配置中的user.name在Git fetch/clone命令中無關緊要,它僅在Git提交中使用。

你是如何執行克隆的?

你用過以下嗎?

git clone ssh://[email protected]:port/repo_name 
+0

是的,這就是我使用克隆的方式。看到赫拉爾多加西亞回答,因爲它解決了我的問題:) –

+0

好的。你是否像Gerardo建議的那樣執行過「git remote show origin」?瞭解問題的根本原因很重要,或者在每次克隆後都要執行「git remote set-url」命令。 –

+0

我在同一時間檢查了/.git/config文件,錯誤的用戶名引起了我的注意。我已經將它改爲我的,並且git fetch開始工作。解決方案@garciadeblas提出的解決方案導致了相同的修復,因爲「git remote show origin」顯示了/.git/config中的數據。所以永久修復是改變/.git/config文件。 –

相關問題