2021年8月13号起,Github在使用https上传项目时,不再支持使用用户名和密码(github的账号密码)进行身份验证,需要使用个人访问令牌。使用用户名和密码会报如下错误

错误信息中有提供解决方案链接。
整体思想就是,在上传项目输入用户名和密码环节
输入密码时,使用个人令牌代替密码,输入即可。
使用方法一:上传新项目
Step一:创建个人令牌
1)登入github账号,点击右上角个人头像,点击settings进入页面
2)点击Developer settings

3)点击Personal access tokens (classic)

进入创建token页面创建即可。
4)生成令牌,需要保存并复制令牌
Github为了安全,关闭页页后将不能再看到生成的token令牌,需要保存好。
Step二:输入密码
1)在github上创建新的项目文件夹


2)上传
git init
git add README.md
git commit -m "first commit"
git branch -M main
git remote add origin https://github.com/yangshujinggirl/seven-baby.git
git push -u origin main
//上传项目
git push -u origin main
Username for 'https://github.com': yanshujinggirl
Password for 'https://yanshujinggirl@github.com':个人令牌
使用方法二:修改现有项目的url
git remote set-url origin https://<your_token>@github.com/<USERNAME>/<REPO>.git
将<your_token>换成你自己得到的令牌。<USERNAME>是你自己github的用户名,<REPO>是你的项目名称
比如
git remote set-url origin https://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@github.com/nlp-greyfoss/typora_notes.git/
报错后,解决方案在报错信息中查找
fatal: unable to access 'https://github.com/<USERNAME>/<REPO>.git':
正确格式
https://<你的令牌TOKEN>@github.com/<USERNAME>/<REPO>.git
使用方法三:clone新版本
对于全新版本,克隆的时候也在github.com前面加个令牌就好了。
git clone https://<TOKEN>@github.com/<user_name>/<repo_name>.git
网友评论