git The requested URL returned error: 403 解决 (git 操作的时候提示没有权限)

git 操作的时候提示没有权限

问题

最近使用git pull更新代码的时候没有权限

在这里插入图片描述

报错内容如下

remote: You do not have permission to pull the repository
fatal: unable to access https://gitee.com/xx/note.git/: The requested URL returned error: 403

当前通过https方式提示报错,但是通过ssh方式去pull代码和push代码都是ok的

查询资料

官方地址

  • The default is not to cache at all. Every connection will prompt you for your username and password.
  • The “cache” mode keeps credentials in memory for a certain period of time. None of the passwords are ever stored on disk, and they are purged from the cache after 15 minutes.
  • The “store” mode saves the credentials to a plain-text file on disk, and they never expire. This means that until you change your password for the Git host, you won’t ever have to type in your credentials again. The downside of this approach is that your passwords are stored in cleartext in a plain file in your home directory.
  • If you’re using a Mac, Git comes with an “osxkeychain” mode, which caches credentials in the secure keychain that’s attached to your system account. This method stores the credentials on disk, and they never expire, but they’re encrypted with the same system that stores HTTPS certificates and Safari auto-fills.
  • If you’re using Windows, you can install a helper called “Git Credential Manager for Windows.” This is similar to the “osxkeychain” helper described above, but uses the Windows Credential Store to control sensitive information. It can be found at https://github.com/Microsoft/Git-Credential-Manager-for-Windows.

文档内容大致如下

​ 默认是不缓存这些内容,每次连接的时候都需要我们来输入用户名和密码

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-QQ3cA5dM-1589965594253)(https://zzy0-0.oss-cn-shanghai.aliyuncs.com/blog/2020-05-20-084148.png)]

  • git为了方便我们使用https方式传输代码不用每次都输入用户名和密码,所以会把这些信息缓存起来
  • 存储方式有以下几种
    • cache
      • 缓存模式将这些信息保存在内存中一段时间。
      • 所有密码都没有存储在磁盘上,并且在15分钟后从缓存中清除。
    • store
      • 存储模式将凭据保存到磁盘上的纯文本文件中,并且它们永不过期。
      • 在我们更改Git主机的密码之前,不必再输入这些信息。
      • 但是密码以明文形式存储在主目录中的普通文件中。
    • 操作系统
      • mac
        • osxkeychain
          • 该模式将凭据缓存在系统帐户附带的安全钥匙串中。 这种方法将凭据存储在磁盘上,并且永不过期,但是它们使用存储HTTPS证书和Safari自动填充的同一系统进行加密。
      • windows
        • Git Credential Manager for Windows

查阅文档可知我在使用git命令的时候提示没有权限很大可能就是因为我之前存储了一份其他的账号密码,而当前我去访问的内容并不是属于这个用户的仓库,所以提示没有权限。

解决

查阅文档文档地址

看到这个命令

git config --list --show-origin

当前命令用来查看git配置的所有信息,执行

扫描二维码关注公众号,回复: 16639553 查看本文章
git config --help

image-20200520165629003

查询影响配置文件

git config --show-origin --get credential.helper

image-20200520165734659

编辑配置文件

看见当前配置信息在/usr/local/git/etc/gitconfig这个目录下,所以去编辑这个目录,删除当前行内容

image-20200520165842529

保存,再次执行

git pull

清除信息成功

发现提示让我输入用户信息

image-20200520165936322

此时原有信息以及清除成功了

恢复存储方式

此时需要恢复成为osxkeychain

不然以后每次都需要输入用户名密码

执行命令

git  config --global  credential.helper  osxkeychain

验证

git config --list --show-origin

image-20200520170444514

修改成功!

猜你喜欢

转载自blog.csdn.net/fvdfsdafdsafs/article/details/106240185