我想在GitExtensions、Sourcetree或任何其他GitGUI中自动使用推拉,每次都不需要在提示中输入用户名和密码。
那么我如何在Git中保存我的凭据?
我想在GitExtensions、Sourcetree或任何其他GitGUI中自动使用推拉,每次都不需要在提示中输入用户名和密码。
那么我如何在Git中保存我的凭据?
当前回答
如果您正在Windows上使用Git凭据管理器。。。
git-config-l应该显示:
credential.helper=manager
但是,如果没有提示您输入凭据,请执行以下步骤:
从“开始”菜单打开“控制面板”选择用户帐户在左侧菜单中选择管理凭据删除与Git或GitHub相关的任何凭据
如果您有代理并且Git服务器位于内部网络上,请确保您没有设置HTTP_PROXY、HTTPS_PROXY、NO_PROXY环境变量。
您还可以使用gitgui测试Git fetch/push/pull,gitgui链接到C:\Users\<username>\AppData\Local\Programs\Git\mingw64\libexec\Git-core中的凭据管理器二进制文件
其他回答
您的问题:
我想在GitExtensions、Sourcetree或任何其他GitGUI中自动使用推拉,而每次都不需要在提示中输入用户名和密码。那么我如何在Git中保存我的凭据?
如果您是github或其他提供商,我建议不要将它们保存在Git中,例如~/.Git凭据,而是将它们视为加密的机密。
将凭据设置为以下格式:
https://your_user_name:your_token@github.com/your_user_name/your_repo_name.git
将其作为加密机密,如secrets.REPOSTORY:
然后,您可以使用它来克隆公共或私有回购及其子模块,以及自动执行推拉操作
# put the credentials in a variable
export REPOSITORY=${{ secrets.REPOSITORY }}
# git clone public or private repos
git clone --recurse-submodules -j8 ${REPOSITORY}
# git pull will do automatic
cd /path/to/the/repo
git pull
# git push to a branch in the repo
git add . && \
git commit -m "Action from ${GITHUB_SHA}" && \
git push --force $REPOSITORY master:$BRANCH
在这种情况下,您需要git凭据助手通过以下命令行告诉git记住您的GitHub密码和用户名:
git config --global credential.helper wincred
如果您使用的是使用SSH密钥的存储库,则需要SSH密钥进行身份验证。
双因素身份验证改变了用户对网站的身份验证方式,但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
要将用户名和用户密码保存到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帐户中
您可以使用git凭据存储将未加密的密码存储在磁盘上,仅受文件系统权限的保护。
实例
git config credential.helper store
git push http://example.com/repo.git
Username: <type your username>
Password: <type your password>
[Several days later]
git push http://example.com/repo.git
[Your credentials are used automatically]
您可以检查存储在文件~/.git凭据中的凭据。
有关更多信息,请访问git credential store-Helper将凭据存储在磁盘上。