如何将github个人访问令牌添加到VisualStudio代码
我收到一封电子邮件,说 Github 将在 2021 年 8 月 13 日之后要求进行令牌身份验证。我想确保在此日期之后我不会中断服务(推/拉)。所以我登录到 Github 并为我的单个 repo创建了一个令牌。
现在我想在 Visual Studio Code 中使用令牌从 Github 推/拉我的 repo,它使用 git 和命令行,我已经安装在我的 Mac 上。
问题- 我该怎么做才能使用我刚刚创建的生成的令牌添加/替换来自 Github 的密码以从我的存储库中推送/拉取?我可以从 Visual Studio Code 执行它还是从终端命令行添加它?
回答
按照以下简单步骤使用个人访问令牌设置 Github 身份验证
-
在 PC 上打开命令行或在 Mac 上打开终端
-
将当前目录设置为您的项目根目录
> cd C:UsersGiddysourcerepoMySampleProject -
运行命令以通过令牌设置远程访问
> git remote set-url origin https://username:token@github.com/username/repository.git例子:
> git remote set-url origin https://sampleuser:a7b19929***58fe65d1c@github.com/sampleuser/sampleproject.git
- This got GitLab authentication working for me after 2FA was made mandatory on the repo.