我想在GitExtensions、Sourcetree或任何其他GitGUI中自动使用推拉,每次都不需要在提示中输入用户名和密码。
那么我如何在Git中保存我的凭据?
我想在GitExtensions、Sourcetree或任何其他GitGUI中自动使用推拉,每次都不需要在提示中输入用户名和密码。
那么我如何在Git中保存我的凭据?
当前回答
在这种情况下,您需要git凭据助手通过以下命令行告诉git记住您的GitHub密码和用户名:
git config --global credential.helper wincred
如果您使用的是使用SSH密钥的存储库,则需要SSH密钥进行身份验证。
其他回答
您可以使用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将凭据存储在磁盘上。
对于Windows用户,这种方式将起作用:
注意:如果您为GitHub启用了双因素身份验证,请暂时禁用它
步骤1转到控制面板→ 用户帐户→ 凭据管理器→ Windows凭据步骤2转到“通用凭据”部分→ 添加通用凭据步骤3-填写字段Internet或网络地址:git。https://github.com用户名:您的GitHub用户名密码:您的GitHub用户名现在单击“确定”。这将将您的GitHub帐户的密码和用户名保存到本地计算机
如果您使用SSH身份验证而不是用户名/密码身份验证,您将更加安全。
如果您使用的是Mac,SSH客户端身份验证将集成到macOS密钥链中。创建SSH密钥后,在终端中键入:
ssh-add -K ~/.ssh/id_rsa
这将向macOS密钥链添加SSH私钥。Git客户端连接到远程服务器时将使用SSH。只要您在服务器上注册了ssh公钥,就可以了。
您的问题:
我想在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