git 代码提交,出现403错误的问题

git 代码提交,出现403错误的问题

git -c diff.mnemonicprefix=false -c core.quotepath=false --no-optional-locks commit -q -F C:\Users\Administrator\AppData\Local\Temp\oyjlj03h.rmt

git -c diff.mnemonicprefix=false -c core.quotepath=false --no-optional-locks push -v --tags --set-upstream origin master:master
remote: [31mYou do not have permission push to this repository[0m
fatal: unable to access 'https://gitee.com/xxxxx/GXLG.git/': The requested URL returned error: 403

Pushing to https://gitee.com/xxxx/GXLG.git
完成时带有错误,见上文。

问题描述

曾用过一个 github 账号进行项目提交,现在使用另一个帐号在同一台机器进行提交时出现错误:

remote: Permission to userName/repositorieName.git denied to OldUserName.
fatal: unable to access 'https://github.com/userName/repositorieName.git/': The requested URL returned error: 403

问题原因

使用第一个账号提交时,系统保存了该账号的用户信息。在使用新帐号提交时,与已保存的用户信息不一致,所以报错。

win10 解决方案

  • 打开 cmd,输入命令:rundll32.exe keymgr.dll,KRShowKeyMgr,出现「存储的用户名和密码」窗口;
  • 将 github 相关的条目删除;
  • 重新执行提交命令,按提示输入账户名及密码后,即可提交成功。

macOS 解决方案

  • 进入钥匙串,在「登录」下找到「github.com」条目并删除;
  • 重新执行提交命令,按提示输入账户名及密码后,即可提交成功。

通用解决方案

进入库目录,找到 .git/confog 文件(macOS 可用终端执行 vi .git/config 直接进入修改),参考内容如下:

[core]
    repositoryformatversion = 0
    filemode = true
    bare = false
    logallrefupdates = true
    ignorecase = true
    precomposeunicode = true
[remote "origin"]
    url = https://github.com/userName/repositorieName.git
    fetch = +refs/heads/*:refs/remotes/origin/*
[branch "other"]
    remote = origin
    merge = refs/heads/other

将用户名加入 [remote "origin"] 中的 url,最终修改为 url = https://[email protected]/userName/repositorieName.git,接下来在提交项目时会要求输入密码。此后,系统将保存密码信息,以后这个库的提交将不再要求输入密码,也不会出现 403 错误。

通用终极解决方案

在 clone 项目时就将用户名加入路径,原路径如下:

git clone -b other https://github.com/userName/repositoryName.git

添加 userName@,该路径修改为:

git clone -b other https://[email protected]/userName/repositoryName.git

接下来在提交项目时会要求输入密码。此后,系统将保存密码信息,以后这个库的提交将不再要求输入密码,也不会出现 403 错误。


部分内容:参考地址
作者:MrDcheng
链接:https://www.jianshu.com/p/efe99888331c
来源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

猜你喜欢

转载自blog.csdn.net/u012118993/article/details/107321123