GitHub改为token验证后,如何提交代码?

Posted 白瑕

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了GitHub改为token验证后,如何提交代码?相关的知识,希望对你有一定的参考价值。


前言

有段时间没往库里交代码了,今天打算把这段时间写的都交上去,结果报出了这个:
remote: Please see https://github.blog/2020-12-15-token-authentication-requirements-for-git-operations/ for more information.

缺少token.

一、获取自己的token

1.进入setting界面

登入GitHub,点击右上角头像旁的下拉列表,

2.进入’Developer settings’

最近他们更新的时候把原来选项的内容放到"Developer settings"选项里了.

3.进入’Generate new token’

生成新的token.

二、New personal access token页面

Note:

Expiration:使用期限,这个token你打算用多长时间再换?(可以无限期)

select scopes:这下面的内容大概是一个权限列表,说的应该是使用这个token登入者所能享受到的权限;


我从上到下列个表吧:
这些中译是我根据自己理解来的,可能与准确功能略有差距,
望大家多多包涵.

权限名
repo"库"repositories的简写
repo:status向库提交
repo_deployment部署库
public_repo访问公开的库
repo:invite
security_events读取改写安全选项
workflow更新代码管理操作工作流
write:packages向GitHub的package Registry(一个包管理工具)上传包
read:public_key读取用户公钥
admin:repo_hook完全控制仓库钩子
write:repo_hook写入:仓库钩子
read:repo_hook读取:仓库钩子
gist创建gist
notifications访问通知
delete_repo删库
write:discussion读写团队交流
read:discussion团队交流中只能读不能说
admin:enterprise企业完全控制
manage_billing:enterprise读写企业账单数据
read:enterprise读取配置数据

最后点击Generate token生成token

三、拿到token后

妥善保存你的token,后面没有机会看到了,如果忘记后要修改会比较麻烦.
你的token会显示在绿色区域;

已经有仓库:为仓库添加token

//这些是一行指令;
git remote set-url origin https://<你的token>@github.com/<GitHub用户名>/<要提交到的库名>.git

原本没有仓库: git clone 添加token

//这些是一行指令;
git clone https://<你的token>@github.com/<GitHub用户名>/<REPO>.git

三、利用token提交代码

第一种方法

这或许也是最常用的方法吧…

1.把要提交的文件放进本地仓库

git add .

2.提交

git commit -m '<对本次提交的备注>'

3.push入库

git push

第二种方法

这是一种很简单的方法,我个人喜欢用这个.
可以不经过拷贝直接将本地仓库push进库(需要两条命令配合使用)

git remote add origin <提交到的仓库地址>

然后

//将已绑定的本地仓库push上去;
git push -u origin master

这个方法也要绑定token,否则会报:

"remote: Please see https://github.blog/2020-12-15-token-authentication-requirements-for-git-operations/ for more information."

总结

这两天找了个element的项目来做,下篇大概率会是element使用方面的文(如果接下来两天内没有让我翻车的重大BUG的话)
感谢你读下来,这些是我的个人见解,可能有些浅薄,如果您能指出我的错误,在下感激不尽了.

以上是关于GitHub改为token验证后,如何提交代码?的主要内容,如果未能解决你的问题,请参考以下文章

GitHub提交时出错,提示需要验证邮箱verify email

2021关于github账户提交需要使用token的使用说明

php通过token验证表单重复提交

全网首发:github已经设置了令牌token,为什么还要验证用户密码

如何验证提交的 Token

如何将代码托管到Github