按照以下简单步骤,使用个人访问令牌设置GitHub身份验证:
在您的PC上打开命令行窗口或Mac上的终端
将当前目录设置为项目根目录
cd C:\Users\Giddy\source\repo\MySampleProject
运行命令以通过令牌设置远程访问。 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
在 Visual Studio Code (Mac) 上进行测试
不需要额外的扩展程序。我只信任官方扩展,抱歉。 GitHub 由 KnisterPeter 开发的扩展程序
cd ~/path/to/your/project
git remote set-url origin https://<personal_access_token>@github.com/<your_username or organization_name>/<repo_name>.git
git push
生成个人访问令牌时,请确保启用工作流程:
您可以键入git remote -v
以查看您的起源或上游。
origin https://github.com/<username>/<repo_name>.git (fetch)
origin https://github.com/<username>/<repo_name>.git (push)
upstream https://github.com/<username>/<repo_name>.git (fetch)
upstream https://github.com/<username>/<repo_name>.git (push)
在设置完git remote set-url origin https://<personal_access_token>@github.com/<your_username>/<repo_name>.git
之后,您的git remote -v
应该是这样的:
origin https://<your_personal_access_token>@github.com/<username>/<repo_name>.git (fetch)
origin https://<your_personal_access_token>@github.com/<username>/<repo_name>.git (push)
git remote set-url origin https://<pat>@code.ini.uzh.ch/CoACH/CoACH-labs.git
。其中<pat>是个人访问令牌。请注意,这里没有用户名(PAT就是用户名)。还要注意,它指定了https连接,但使用了.git形式的连接。 - undefined为启用 Visual Studio Code GitHub 支持,请设置个人访问令牌。
前往 设置 → 开发者设置 → 个人访问令牌
点击生成新令牌
返回 Visual Studio Code 并打开命令面板 (Ctrl + Shift + P)
输入 GitHub:设置个人访问令牌
粘贴新生成的令牌的值
git config credential.helper
结果。
如果它是manager或manager-core,请使用git credential-manager-core erase
删除旧密码。github.com
条目及其关联值——密码)git credential-manager-core get
将读取该旧值)printf "protocol=https\nhost=github.com\nusername=<yourGitHubAccountName>"|git credential-manager-core erase
git credential-manager-core store
存储令牌:printf "protocol=https\nhost=github.com\nusername=<yourGitHubAccountName>\npassword=<newToken>"|git credential-manager-core store
manager
而非 manager-core
,则将 credential-manager-core
替换为 credential-manager
。
Visual Studio Code 将使用该凭据助手,并将新的“密码”(令牌)存储到远程站点。
git: 'credential-manager-core' is not a git command. See 'git --help'.
credential-manager-core
替换为credential-osxkeychain
(https://dev59.com/XWgu5IYBdhLWcg3wzKAc#28007050),或者您可以通过图形方式完成:https://docs.github.com/en/github/using-git/updating-credentials-from-the-macos-keychaina - VonCgit config credential.helper
,但什么也没有得到。 - Ben Whitmoreerase
)? - Peter Mortensen我在使用GitHub密码验证时,遇到了Visual Studio Code的“你不能再使用密码验证GitHub”的问题。
我使用的是Mac电脑,所以默认安装了Git(v2.21)。
我尝试了以下步骤,现在可以通过Visual Studio Code无误地检入代码(请注意,此方法使用Microsoft Git凭据管理器核心 - 请参见此处):
复制以下行并粘贴到您的Visual Studio Code终端中
git remote set-url origin https://<TOKEN>@github.com/<USERNAME>/<REPOSITORYNAME>.git
git remote set-url origin https://asdlkuresdflj23433423lj234@github.com/brother/sampleapp.git
.git/config
文件中。 - SamB要查看与GitHub身份验证相关的输出:
目前我使用的是Visual Studio Code v1.56.0版本。
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
[remote "origin"]
url = https://YourGitlabName:YourToken@gitlab.com/YorRepo
fetch = +refs/heads/*:refs/remotes/origin/*
[branch "main"]
remote = origin
merge = refs/heads/main
[user]
name = YourGitlabName
email = YourGitlabE-mail
我曾经遇到同样的问题,最终成功地出现了“登录 GitHub”提示并完成了身份验证。基本上,在浏览器窗口中单击“授权 Visual Studio Code”后,您需要执行以下确认页面:
Success!
Authorization was successful. You will be redirected back to Visual Studio Code
Didn't work? If you aren't redirected, you can add the token manually.
**Your authorization token:**
vscode://vscode.github-authentication/did-authenticate?windowid=1&code=[Not-A+Real+Token)SJ###AASDf
......... etc
切换回VS Code (可能已经自动聚焦),然后选择'不再提示'或者其他类似的消息...然后你就可以看到并点击'登录GitHub...'的提示了
希望这能帮助到某些人...因为尽管听起来很简单,但是当关闭提示或选择“显示Git日志”选项时,VS Code并不会提示。