现象描述:
好久没推代码到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
包含两种:
- Fine-grained personal access tokens
- 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):
- 点击
Settings
:
- 点击
Develop Setting
- 点击
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