【Git】GitHub创建Personal access tokens 利用SourceTree连接Git仓库

SourceTree使用版本:SourceTree v4.1.2

git --no-optional-locks -c color.branch=false -c color.diff=false -c color.status=false -c diff.mnemonicprefix=false -c core.quotepath=false -c credential.helper=sourcetree fetch origin

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: unable to access 'https://github.com/xxxx/xxxx.git/: The requested URL returned error: 403

Completed with errors, see above

我们进行提交和拉取如果遇到以上的错误则是,管理员修改了验证方式,原来通过账号与密码进行连接克隆的远程仓库进行远程操作时,无法通过验证,需要自己在github创建Personal access tokens,就是自己的个人令牌,并在SourceTree添加账户使之能够通过验证;

image.png

可以参见官方文档来创建个人令牌 :
Creating a personal access token:
https://docs.github.com/en/github/authenticating-to-github/keeping-your-account-and-data-secure/creating-a-personal-access-token#creating-a-token

下面是创建个人token的步骤:

1.在GitHub创建自己的Personal access tokens;点击右上角头像选择Settings;

image.png

2.选择Settings -> 左侧栏Developer Settings -> Personal access tokens,然后点击Generate new token创建你的一个你的个人token;

image.png

3.下一步会要求输入你的git密码;

image.png

4.然后填写你的相关信息;

Note填写你的token名字,用于区分其他你创建的token;

Expiration则是选择你的token的过期时间;

Select scopes选择你的token的权限,每个权限后面都有对应的功能解释;

我这里选择了admin:repo_hook, delete_repo, repo;

然后点击最下面的按钮生成你的personal access token;

image.png

5.Generate token点击后会生成你的token,需要进行复制并保存,后续不可见,否则需要重新生成token;

image.png

下面则是在SourceTree怎么添加你的账户;

1.打开SourceTree,选择远程的选项卡,显示如下,没有任何仓库;

image.png

2.点击上方的连接… 按钮或者通过SourceTree的偏好设置->账户都可以调出下面的窗口;

image.png

3.点击左下角添加;托管主机为GitHub,你使用的什么主机就选择什么主机;授权类型为基础,不是OAuth;用户名填写你的Github名字,而不是你的账号邮箱;密码则填写你生成的Personal access tokens;协议选择HTTPS,然后保存;

image.png

4.SourceTree则会去尝试连接,连接错误请检查用户名和token是否正确,如果生成了多个token,请填写最新生成的token;连接成功后,账户会显示一个你的账号,SourceTree会显示你的git下的对应工程,你可以直接进行克隆操作;

image.png

如有错误,欢迎指出,以上。

你可能感兴趣的:(【Git】GitHub创建Personal access tokens 利用SourceTree连接Git仓库)