git拉取失败,没有权限:Please make sure you have the correct access rights and the repository exist

git拉取项目,出现以下:

fatal: Could not read from remote repository.
​
Please make sure you have the correct access rights
and the repository exists.

提示错误显示为没有权限,主要是因为不同设备上的ssh公钥不同,导致git仓库公钥出现问题,需要重新重新生成ssh公钥即可解决

 首先在git官网下载git工具Git - Downloading Package (git-scm.com)

1.重置用户名和邮箱:

打开Git Bash 进入Git命令,在需要提交的项目根目录下,
输入以下命令来设置名字和邮箱(该处填写的名字和邮箱为github上的用户名和邮箱)
git config --global user.name "你的名字" //xxx
git config --global user.email "你的邮箱" //[email protected]

2.删除known_hosts文件:

打开C盘用户下的.ssh文件夹,
地址是C:\Users(用户)\Administrator\.ssh,删除known_hosts文件

3.生成公钥认证所需的公钥和私钥文件,在C盘.shh文件夹里打开git bash,Git输入命令:

ssh-keygen -t rsa -C "你的邮箱" y之后就一直回车直到完成所有步骤

4.复制公钥:

完成第3步后,此时.ssh文件夹里出现了两个文件,分别为 id_rsa(密钥)和id_rsa.pub(公钥),
用记事本打开id_rsa.pub并全选复制其中的内容,密钥格式是以邮箱结尾的

5.设置公钥:

进入自己的git仓库主页,进入设置界面,进行ssh密钥设置

 6.在项目目录里打开Git Bash,输入命令:

git clone git@xxxxxxx 按回车,然后出现一串字,并输入yes,再回车,成功

猜你喜欢

转载自blog.csdn.net/weixin_43928112/article/details/131196951