目录
生成Token
登录GitHub,在GitHub右上角点击个人资料头像,点击Settings →Developer Settings → Personal access tokens (classic)。
在界面上选择点击【Generate new token】,填写如下界面
![](https://img-blog.csdnimg.cn/direct/d945c81285444e0791418e9126c10870.png)
根据需要进行勾选,通常需要将repo及子项进行勾选。
生成完毕后,得到ghp_xxxxxxxxx的 Token类似如下:
![](https://img-blog.csdnimg.cn/direct/4dfde3d0cc1544d0bfc29e8fb92f90f2.png)
使用Token-手工修改
如果为已经clone过的本地仓,则打开本地仓下的 .git/config 的配置文件。对该配置文件中remote下的url地址进行修改。
bash
#修改前通常为:https://github.com/<USERNAME>/<REPO>.git
#修改后如下
https://<yourToken>@github.com/<USERNAME>/<REPO>.git
除了直接修改配置文件,也可以通过以下命令修改
bash
git remote set-url 远端仓别名 新的URL地址
使用Token-自动
如果在与远端仓进行交互操作过程中,自动弹出需要账户/密码,可按图所示进行操作。
![](https://img-blog.csdnimg.cn/direct/e405e55bf3444e2398797b739d2eecb9.png)
![](https://img-blog.csdnimg.cn/direct/d92b97d8fa964560b399508ffff57d36.png)
也有可能在push时自动弹出如下对话框
![](https://img-blog.csdnimg.cn/direct/622b22db93f54ab081c4aaeefe6a8691.png)