我想在GitExtensions、Sourcetree或任何其他GitGUI中自动使用推拉,每次都不需要在提示中输入用户名和密码。
那么我如何在Git中保存我的凭据?
我想在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
您的问题:
我想在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
GitHub的建议现在已经改变,最好的方法也是最简单的。此处显示详细信息
安装Github官方cli。例如,对于mac:brew install gh。在终端中键入gh-auth-login,然后按照提示进行操作。
您可以编辑~/.gitconfig文件以存储凭据:
sudo nano ~/.gitconfig
应该已经有了
[user]
email = your@email.com
user = gitUSER
您应该在该文件的底部添加以下内容。
[credential]
helper = store
我推荐这个选项的原因是因为它是全局的,如果在任何时候你需要删除这个选项,你就知道该去哪里更改它。
仅在个人计算机中使用此选项。
然后,当您拉|clone|输入Git密码时,通常,密码将以以下格式保存在~/.Git凭据中
https://gituser:gitpassword@domain.xxx
其中DOMAIN.XXX可以是github.com、bitbucket.org或其他
请参阅文档。
重新启动终端。
git config --global user.name "your username"
git config --global user.password "your password"
检查
git config --list