我想在GitExtensions、Sourcetree或任何其他GitGUI中自动使用推拉,每次都不需要在提示中输入用户名和密码。
那么我如何在Git中保存我的凭据?
我想在GitExtensions、Sourcetree或任何其他GitGUI中自动使用推拉,每次都不需要在提示中输入用户名和密码。
那么我如何在Git中保存我的凭据?
当前回答
对于Windows用户,请查看.gitconfig文件并检查为凭据助手配置了什么。如果您有以下内容。。。
[凭证“helperselector”]selected=绞车
您将在Windows凭据管理器中找到凭据。
您可以在那里编辑凭证。
注意:Wincred已被弃用,请参阅。。。
https://github.com/Microsoft/Git-Credential-Manager-for-Windows#notice-该项目不再处于警告状态
因此,您可能需要重新配置Git以使用内置的Git凭据管理器。。。
git config --global credential.helper manager
其他回答
对于Windows用户,这种方式将起作用:
注意:如果您为GitHub启用了双因素身份验证,请暂时禁用它
步骤1转到控制面板→ 用户帐户→ 凭据管理器→ Windows凭据步骤2转到“通用凭据”部分→ 添加通用凭据步骤3-填写字段Internet或网络地址:git。https://github.com用户名:您的GitHub用户名密码:您的GitHub用户名现在单击“确定”。这将将您的GitHub帐户的密码和用户名保存到本地计算机
只需将您的凭据放入URL,如下所示:
https://Username`**:**`Password`**@**`github.com/myRepoDir/myRepo.git`
您可以这样存储:
git remote add myrepo https://Userna...
…使用它的示例:
git push myrepo master`
现在就是列出URL别名:
git remote -v
…以及删除其中一个的命令:
git remote rm myrepo
推荐的安全方法:SSH
创建SSH GitHub密钥。转到github.com→ 设置→ SSH和GPG密钥→ 新SSH密钥。现在将您的私钥保存到计算机。
然后,如果私钥保存为~/.ssh/目录中的id_rsa,我们将其添加为身份验证:
ssh-add -K ~/.ssh/id_rsa
更安全的方法:缓存
我们可以使用git凭据缓存在一段时间内缓存用户名和密码。只需在CLI(终端或命令提示符)中输入以下内容:
git config --global credential.helper cache
您还可以按如下方式设置超时时间(以秒为单位):
git config --global credential.helper 'cache --timeout=3600'
截至2021,HTTPS远程有一个安全、用户友好的跨平台解决方案。不再输入密码!不再有SSH密钥!不再有个人访问令牌!
安装GitHub开发的Git凭据管理器(下载)。它支持对GitHub、BitBucket、Azure和GitLab的无密码浏览器内OAuth认证。这意味着您可以在GitHub和其他平台上启用双因素身份验证,大大提高了帐户的安全性。
推送时,您可以选择身份验证方法:
> git push
Select an authentication method for 'https://github.com/':
1. Web browser (default)
2. Device code
3. Personal access token
option (enter for default): 1
info: please complete authentication in your browser...
在Linux上,需要一点点设置。以下内容将凭据缓存在内存中20小时,因此您每天最多只能进行一次身份验证。
git-credential-manager-core configure
git config --global credential.credentialStore cache
git config --global credential.cacheoptions "--timeout 72000"
熟悉gnomekeyring或KWallet的高级用户可能更喜欢将凭证存储更改为libsecret。
外观配置(文档):
首选在终端而不是GUI中选择身份验证方法(点击次数较少)始终使用浏览器方法,而不是每次都被询问(甚至更少的按键)
git config --global credential.guiPrompt false
git config --global credential.gitHubAuthModes browser
除了编辑~/.gitconfig文件外,如果从命令行调用,还可以执行以下操作:
git config --local --edit
or
git config --global --edit
在默认文本编辑器中编辑git配置文件
您还可以使用命令行直接编辑git配置文件(无需编辑器)
git config --local user.name 'your username'
git config --local user.password 'your password'
or
git config --global user.name 'your username'
git config --global user.password 'your password'
请注意,始终使用单引号。如果您使用双引号,您的用户名和密码可能会使用一些会破坏密码的字符。
--local或--global表示为项目或OS用户保存配置参数。