我想在GitExtensions、Sourcetree或任何其他GitGUI中自动使用推拉,每次都不需要在提示中输入用户名和密码。
那么我如何在Git中保存我的凭据?
我想在GitExtensions、Sourcetree或任何其他GitGUI中自动使用推拉,每次都不需要在提示中输入用户名和密码。
那么我如何在Git中保存我的凭据?
当前回答
您的问题:
我想在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 credentials是运行git-config--globalcredential.helper store时存储用户名和密码(访问令牌)的位置,这是其他答案所建议的,然后键入用户名和密码或访问令牌:
https://${username_or_access_token}:${password_or_access_token}@github.com
因此,为了保存用户名和密码(访问令牌):
git config —-global credential.helper store
echo “https://${username}:${password_or_access_token}@github.com“ > ~/.git-credentials
这对于GitHub机器人非常有用,例如,通过为不同分支设置规则来解决同一Docker Hub存储库中的Chain自动化构建,然后通过在Docker Hub中的post_push钩子中推送该规则来触发它。
堆栈溢出就是一个例子。
以前的答案对我来说都不管用。每次我想取东西或拉东西时,我都会得到以下答案:
输入密钥“/Users/myusername/.ssh/id_rsa”的密码:
适用于Mac
我可以通过以下方式阻止它询问我的密码:
通过运行:vi~/.ssh/config打开config添加了以下内容:UseKeychain yes保存并退出:按Esc,然后输入:wq!
对于Windows
我能够使用此Stack Exchange帖子中的信息使其发挥作用:如何避免每次推到Bitbucket时被询问密码
注意:此方法以明文形式将凭据保存在电脑磁盘上。计算机上的每个人都可以访问它,例如恶意NPM模块。
Run
git config --global credential.helper store
then
git pull
提供用户名和密码,这些详细信息稍后将被记住。凭证存储在磁盘上的文件中,磁盘权限为“仅用户可读/可写”,但仍为明文。
如果以后要更改密码
git pull
将失败,因为密码不正确,git然后从~/.git凭据文件中删除有问题的用户+密码,因此现在重新运行
git pull
以提供一个新密码,以便与之前一样工作。
您可以使用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将凭据存储在磁盘上。
打开凭据助手,以便Git将您的密码保存在内存中一段时间:
在终端中,输入以下内容:
# Set Git to use the credential memory cache
git config --global credential.helper cache
默认情况下,Git将缓存您的密码15分钟。
要更改默认密码缓存超时,请输入以下内容:
# Set the cache to timeout after 1 hour (setting is in seconds)
git config --global credential.helper 'cache --timeout=3600'
来自GitHub帮助。