Github在七夕搞事情

865 阅读1分钟

事由

有一个自己经常更新的博客托管在Github上.因为之前都是用Github的账号和密码进行推送代码,上周还正常,今天在去push的时候发现了问题,报错如下:

git --no-optional-locks -c color.branch=false -c color.diff=false -c color.status=false -c diff.mnemonicprefix=false -c core.quotepath=false -c credential.helper=sourcetree push -v --tags origin refs/heads/master:refs/heads/master 
Pushing to https://github.com.cnpmjs.org/AnsonZnl/v-blog.git
remote: Support for password authentication was removed on August 13, 2021. Please use a personal access token instead.
remote: Please see https://github.blog/2020-12-15-token-authentication-requirements-for-git-operations/ for more information.
fatal: unable to access 'https://github.com.cnpmjs.org/AnsonZnl/v-blog.git/': The requested URL returned error: 403
Completed with errors, see above

大概意思是,从2021年8月13日开始,密码凭证就不能用了,也就是说不能使用账号密码进行代码推送操作了,如需推送要改为 personal token 形式。

官方通知在这里:Git password authentication is shutting down

解决方法

既然不能使用密码,那其实就只能使用 SSH 或者 personal token 了。

SSH 大家都熟(不会去百度),或者看 GitHub 的SSH文档-中文

当然你可以使用使用 personal token 的方式,文档在这里Creating a personal access token

生成 Token 后可以直接使用。

git remote set-url origin https://<your_token>@github.com/<USERNAME>/<REPO>.git
  • <your_token>:换成你自己得到的token
  • :是你自己github的用户名
  • :是你的仓库名称

亲测成功,希望能帮到大家。

参考