问题
I got an issue with accessing the external repository on gerrit through git. When I try to git fetch in cloned repository directory (clone works well) I get:
> 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.
But when I do it directly with repository ssh address and username I get:
> git fetch ssh://username@ip:port/repo_name
remote: Counting objects: xxxx, done
remote: Finding sources: 100% (xxx/xxx)
etc...
So the direct git fetch seems to work well. I've tried to set different usernames with:
git config --global user.name "username"
But with no use - I still get Permission denied (publickey). Again - git clone works fine.
Any ideas how to fix that?
回答1:
Frist, check the current URL used to fetch:
git remote show origin
Then, if the fetch url does not match, change it using the following command:
git remote set-url origin ssh://username@ip:port/repo_name
回答2:
The user.name on Git config doesn't matter in Git fetch/clone command it's used only in Git commits.
How did you execute the clone?
Have you used the following?
git clone ssh://username@ip:port/repo_name
来源:https://stackoverflow.com/questions/42832120/git-fetch-in-repo-dir-permission-denied-but-working-with-direct-link-with-user