我想在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
其他回答
以前的答案对我来说都不管用。每次我想取东西或拉东西时,我都会得到以下答案:
输入密钥“/Users/myusername/.ssh/id_rsa”的密码:
适用于Mac
我可以通过以下方式阻止它询问我的密码:
通过运行:vi~/.ssh/config打开config添加了以下内容:UseKeychain yes保存并退出:按Esc,然后输入:wq!
对于Windows
我能够使用此Stack Exchange帖子中的信息使其发挥作用:如何避免每次推到Bitbucket时被询问密码
git config --global user.name "your username"
git config --global user.password "your password"
检查
git config --list
GitHub的建议现在已经改变,最好的方法也是最简单的。此处显示详细信息
安装Github官方cli。例如,对于mac:brew install gh。在终端中键入gh-auth-login,然后按照提示进行操作。
您的问题:
我想在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 config --global user.name "fname lname"
git config --global user.email "example@gmail.com"
git config --global user.password "secret"
获取特定设置,
git config --global --get user.name
git config --global --get user.email
git config --global --get user.password
正在获取所有Git设置:
git config --list --show-origin