My solution for Git Client Error: Permission denied (publickey)

在使用Git客户端的过程中遇到的问题以及解决方案分享。

我之前已经安装Git客户端并且使用Git开发过公司项目,也已经正确生成PublicKey并且添加到SSH keys on github of my account,但是当我想从github上克隆另一个客户端push的代码的时候一直报错:

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

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

在开发公司项目的时候完全没有遇到什么权限问题,应该是之前使用Git的过程中做了某些配置导致的这个问题,运行 git config --global --list 命令Check全局配置信息

git config --global --list

发现remote.origin.url和remote.gerrit.url配置的远程仓库是之前公司的github仓库地址,在全局配置里将其清除

git config --global --unset remote.origin.url
git config --global --unset remote.gerrit.url

重新克隆仓库一切正常!!!

一般情况下,每个具体项目的远程仓库都配置在 localRepo/.git/config中,也可以cd到localRepo通过命令 git config --list查看。

Git使用,按照git-scm.com上的步骤,即使遇到问题也也肯定都有解决方案,我这次遇到的问题比较措手不及而已。

原文地址:https://www.cnblogs.com/title/p/6416520.html