【github】启用 personal access token作为登录凭证

865 阅读1分钟

Github Docs For PAT

20218 月 13 日- 所有经过身份验证的 Git 操作都需要令牌(或 SSH 密钥)身份验证。

前言

github的官方表示,github于2020年11月13日起逐步的推行使用token认证代替原来的用户名密码认证,该项工作于2021年年中左右推行完毕。所以一些历史上我们使用用户名+密码拉取的github仓库在进行git pull \ push \ fetch等操作时,会报如下错误:

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.

image.png

解决方法

创建一个token(personal access token) ;

官方文档创建token

配置git项目

  • 在项目文件夹中执行配置命令
    git config --edit
    
  • 远程仓库配置git用户名以及token
    • githubUsername替换为你的git用户名
    • yourToken替换为你上一步生成的token;
[remote "origin"]
        url = https://githubUsername:yourToken@github.com/repositoryName
        fetch = +refs/heads/*:refs/remotes/origin/*