让git使用存储在github客户端中的凭据(或直接将令牌存储在git中)



为了启用对github repo的推送,我应该使用"令牌认证";。

创建令牌后,我应该将其存储在本地github客户端中。https://docs.github.com/en/get-started/getting-started-with-git/caching-your-github-credentials-in-git.

如何使本地github客户端与本地git交互?我只想在github repo中使用git push,并使用存储的令牌进行身份验证。

或者,我会提交本地github客户端,并将令牌直接存储在git中,但我没有找到如何实现这一点。

Git没有用于存储凭据的内置存储,而是依赖于"凭据管理器"来存储凭据并在需要时反馈。

最常见的凭据管理器是Git凭据管理器(GCM((以前是GCM核心(。可以将其配置为将凭据存储在操作系统安全存储中,或将其加密存储在磁盘上。

curl -LO https://raw.githubusercontent.com/GitCredentialManager/git-credential-manager/main/src/linux/Packaging.Linux/install-from-source.sh &&
sh ./install-from-source.sh &&
git-credential-manager-core configure

或者,如果您依赖Windows Subsystem for Linux,您也可以将其搭载在Windows凭据存储中。

在您的.gitconfig中添加:

git config --global credential.helper "/mnt/c/Program Files/Git/mingw64/libexec/git-core/git-credential-manager-core.exe"
git config --global credential.https://dev.azure.com.useHttpPath true

更多详细信息:

  • 凭证存储上的Git文档
  • Git凭据管理器
  • WSL上的Git凭据管理器

最新更新