我想在GitExtensions、Sourcetree或任何其他GitGUI中自动使用推拉,每次都不需要在提示中输入用户名和密码。

那么我如何在Git中保存我的凭据?


当前回答

只需将您的凭据放入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

其他回答

双因素身份验证改变了用户对网站的身份验证方式,但Git仍然假设用户可以从内存中键入密码。

介绍git credential oauth:一个git凭据助手,可以使用oauth安全认证GitHub、GitLab、BitBucket和其他伪造文件。

没有更多密码!不再有个人访问令牌!不再有SSH密钥!第一次推送时,助手将打开浏览器窗口进行身份验证。缓存超时内的后续推送不需要交互。

从安装https://github.com/hickford/git-credential-oauth/releases/

配置方式:

git config --global --unset-all credential.helper
git config --global --add credential.helper "cache --timeout 7200" # two hours
git config --global --add credential.helper oauth

对于Windows用户,这种方式将起作用:

注意:如果您为GitHub启用了双因素身份验证,请暂时禁用它

步骤1转到控制面板→ 用户帐户→ 凭据管理器→ Windows凭据步骤2转到“通用凭据”部分→ 添加通用凭据步骤3-填写字段Internet或网络地址:git。https://github.com用户名:您的GitHub用户名密码:您的GitHub用户名现在单击“确定”。这将将您的GitHub帐户的密码和用户名保存到本地计算机

对于Windows用户,请查看.gitconfig文件并检查为凭据助手配置了什么。如果您有以下内容。。。

[凭证“helperselector”]selected=绞车

您将在Windows凭据管理器中找到凭据。

您可以在那里编辑凭证。

注意:Wincred已被弃用,请参阅。。。

https://github.com/Microsoft/Git-Credential-Manager-for-Windows#notice-该项目不再处于警告状态

因此,您可能需要重新配置Git以使用内置的Git凭据管理器。。。

git config --global credential.helper manager

注意:此方法以明文形式将凭据保存在电脑磁盘上。计算机上的每个人都可以访问它,例如恶意NPM模块。

Run

git config --global credential.helper store

then

git pull

提供用户名和密码,这些详细信息稍后将被记住。凭证存储在磁盘上的文件中,磁盘权限为“仅用户可读/可写”,但仍为明文。

如果以后要更改密码

git pull

将失败,因为密码不正确,git然后从~/.git凭据文件中删除有问题的用户+密码,因此现在重新运行

git pull

以提供一个新密码,以便与之前一样工作。

要将用户名和用户密码保存到github帐户中,只需按顺序运行这些命令。

git config --global user.name "userName"
git config --global user.email "usernam@gmail.com"
git config --global user.password "userPassword"
git config --global credential.helper store
git config --list --show-origin

然后使用以下命令生成密钥:

ssh-keygen -t rsa -C "useremail@gmail.com"

注意:复制创建id_rsa文件的文件位置然后转到该文件位置-->打开gitbash或命令提示符-->运行命令-cat id_rsa.pub

将显示SSH密钥,复制此SSH密钥并将其粘贴到gihub/gitlab帐户中