0
点赞
收藏
分享

微信扫一扫

GitHub配置token拉取和上传

数数扁桃 2022-02-08 阅读 107

8月13日开始,github开始停止使用账号密码拉取项目。
所以13号之后使用命令操作github上项目,比如git pull拉取代码的话,就会提示如下的错误:

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: Authentication failed for 'https://github.com/wubomichael/k3s-ansible.git/'

github的本意是想通过令牌替代账号密码这种不安全的操作,由于是强制的,所以也只能更新令牌了。
操作如下:

一.通过github创建新的access token

流程如下:
1.右上角头像->Setttings->Developer settings->Personal access tokens->Generate new token
2.日期我选择No expiration(无限期),授权范围的话全部选上。

  • 填写Note,例如:ellisonpei;
  • 选择Expiration,选择无期限;
  • 选择Select scopes,全选。

3.点击Generate token生成,令牌保存成功。记住,这个生成的令牌一定要保存好。

二.切换登录方式,使用最新的令牌登录。

1.切换到git项目,使用下面的命令清空本地存储的账号密码。
git config --local credential.helper ""
2.配置新的令牌访问。
直接用文本编辑器打开git项目根目录中 .git/config文件。(PS:注意.git是隐藏文件夹)
按照如下格式,修改url和fetch即可:

[root@jettoloader k3s-ansible-master]# cat .git/config 
[core]
	repositoryformatversion = 0
	filemode = true
	bare = false
	logallrefupdates = true
[remote "origin"]
	url = https://<<name:token>>@github.com/<<name>>/k3s-ansible.git
	fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
	remote = origin
	merge = refs/heads/master
[credential]
	helper =
举报

相关推荐

0 条评论