使用https推送代码到github报“ Support for password authentication was removed on August 13, 2021”

现象描述:

好久没推代码到github了,今天新建一个仓库,推送本地代码到github,需要填入用户名和密码:
在这里插入图片描述
填入用户名和密码点击Login按钮,竟然报这个:
在这里插入图片描述
上述文字如下:

git -c diff.mnemonicprefix=false -c core.quotepath=false --no-optional-locks push -v --tags --set-upstream github master:master
libpng warning: iCCP: known incorrect sRGB profile
libpng warning: iCCP: known incorrect sRGB profile
Logon failed, use ctrl+c to cancel basic credential prompt.
remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.


Pushing to https://github.com/lishuangquan1987/优快云Exporter.git
完成时带有错误,见上文。

问题解决

既然上述说到https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls看看,那我们去看看:
在这里插入图片描述
原来github改变了规则,上述输入用户名和密码中的密码不是登录github的密码,而是personal access token,那么如何获取这个token呢?

这里的personal-access-token包含两种:

  1. Fine-grained personal access tokens
  2. Personal access tokens (classic)
    我们使用Personal access tokens (classic).
    参考:https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens#creating-a-personal-access-token-classic
按照步骤创建Personal access tokens (classic):
  1. 点击Settings:
    在这里插入图片描述
  2. 点击Develop Setting
    在这里插入图片描述
  3. 点击Personal access token,选择Tokens(classic),如果之前没有生成过,就点击Generate new token,如果生成过,那就用以前的,我这里生成了一个for git use的token(可以设置永不过期):
    在这里插入图片描述
    在这里插入图片描述
    然后复制Token,填入推送代码时弹框要求输入密码的地方:

在这里插入图片描述

更正一下

后来发现上面的方法不行了,得这样设置:
设置项目的url时,比如项目的git地址是:https://github.com/lishuangquan1987/try_win32.git
那么添加到git的远程地址时,需要设置成:https://your_token@github.com/lishuangquan1987/try_win32.git

如下图source tree的设置所示:
在这里插入图片描述

也可以使用命令设置:

git remote set-url github https://ghp_ygblKYuCmhUdgfjqUjPRGYx5553fwcc3oLPn8@github.com/lishuangquan1987/try_win32.git

注意:我这里的远端取名叫github,一般默认情况是origin

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值