问题:在使用git push上传代码时,出现了如下的报错:

$ git push
remote: Password authentication is temporarily disabled as part of a brownout. Please use a personal access token instead.
remote: Please see https://github.blog/2020-07-30-token-authentication-requirements-for-api-and-git-operations/ for more information.
fatal: unable to access 'https://github.com/zjxht62/learnJava.git/': The requested URL returned error: 403

大体意思就是说之前密码验证登录的方式已经不能用了,需要改用密钥(access token)的方式,那么如何更改为使用token登录的方式呢?下面记录这一过程:
参考博客

  1. 从github上获得个人token,并记录保存下来,之后会用
  2. 由于我之前设置存储了git登录的账户和密码,现在密码有改动,因此需要把之前的替换掉,于是我参考上面的博客清理了之前保存的账密信息:
git config --global --unset credential.helper
  1. 然后再本地git仓库中使用git push发现需要重新输入账密,输入个人账户名和密码,注意这里的密码就是第1步中得到的token,然后发现git push成功。但是我不想每次push的时候都重新输入一边账密,而且token很长,输入耗时,因此想把账密存储下来,下次push的时候自动跳过输入账密的步骤。于是我根据博客中提供的方法,在终端中输入:
git config --global credential.helper store

然后再git push,问题出现了:git push时又出现了最开始的问题:

$ git push
remote: Password authentication is temporarily disabled as part of a brownout. Please use a personal access token instead.
remote: Please see https://github.blog/2020-07-30-token-authentication-requirements-for-api-and-git-operations/ for more information.
fatal: unable to access 'https://github.com/zjxht62/learnJava.git/': The requested URL returned error: 403

然后我又重置了一下:

git config --global --unset credential.helper

然后再git push,发现又可以输入账密正常push了,反复这么操作几次后都是这个现象,因此判断在执行了

git config --global credential.helper store

命令后,新生成的token没有生效,貌似还是在旧的密码进行验证,于是我查了下git存储账密的文件,目标锁定在了两个文件:
(1)本地git仓库中的隐藏文件夹.git中的config文件
(2)home目录下的隐藏文件.git-credentials
Note:隐藏文件可用“Ctrl+H”进行显示/隐藏的切换
打开config文件发现没有账密信息,打开.git-credentials文件发现存储有账户和之前的密码信息,把新生成的token替换旧的密码并保存,然后在终端中重新输入

git config --global credential.helper store

再git push,成功!说明新生成的token起作用了

Logo

瓜分20万奖金 获得内推名额 丰厚实物奖励 易参与易上手

更多推荐