我想在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将您的密码保存在内存中一段时间:

在终端中,输入以下内容:

# 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帮助。

将用户名和密码存储在.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钩子中推送该规则来触发它。

堆栈溢出就是一个例子。

我认为缓存凭据比永久存储更安全:

git config --global credential.helper 'cache --timeout=10800'

现在,您可以输入用户名和密码(git pull或…),并在接下来的三个小时内继续使用git。

它很好,很安全。

超时的单位是秒(在本例中为三小时)。

对于全局设置,打开终端(从任何位置),运行以下命令:

  git config --global user.name "your username"
  git config --global user.password "your password"

这样,您计算机上的任何本地Git存储库都将使用该信息。

您可以通过执行以下操作为每个存储库单独配置:

在存储库文件夹中打开终端。运行以下操作:git-config user.name“您的用户名”git-config user.password“您的密码”

它只影响该文件夹(因为您的配置是本地的)。

以前的答案对我来说都不管用。每次我想取东西或拉东西时,我都会得到以下答案:

输入密钥“/Users/myusername/.ssh/id_rsa”的密码:


适用于Mac

我可以通过以下方式阻止它询问我的密码:

通过运行:vi~/.ssh/config打开config添加了以下内容:UseKeychain yes保存并退出:按Esc,然后输入:wq!


对于Windows

我能够使用此Stack Exchange帖子中的信息使其发挥作用:如何避免每次推到Bitbucket时被询问密码