如何更新Git的密码?

时间:2013-11-25 14:15:14

标签: macos git change-password

我正在使用BitBucket和Xcode以及Git进行版本控制,最近我更改了所有密码(感谢Adobe!)。

不出所料,我不再能够将我的本地提交推送到BitBucket上的存储库(Authentication failed for 'https://______.git'),但我忘记了如何更新iMac上的缓存密码。不知何故,我一直无法在谷歌或Stack Overflow上找到它,虽然在我看来它应该是相当简单的......

29 个答案:

答案 0 :(得分:599)

要在macOS上解决此问题,您可以使用

git config --global credential.helper osxkeychain

用户名和密码提示符将与您的下一个Git操作一起显示(拉,克隆,推送等)。

对于Windows,它是具有不同参数的相同命令:

git config --global credential.helper wincred

答案 1 :(得分:350)

MacOS Sierra 10.12.4

中没有其他答案适用于我

以下是我必须做的事情:

git config --global --unset user.password

然后运行你的git命令(例如git push)并重新输入你的用户名和密码。

答案 2 :(得分:135)

我唯一可以修改git密码的方法是转到Windows中的凭据管理器(Windows键+键入“凭据”),然后在Windows凭据通用凭据下编辑git条目。 注意:未按字母顺序列出

答案 3 :(得分:133)

在具有Git的Windows 10中

删除/更新存储在>>控制面板\所有控制面板项\凭据管理器中的Windows凭据中的相关凭据

enter image description here

答案 4 :(得分:70)

我遇到了同样的问题,并且接受的答案对我没有帮助,因为密码没有存储在钥匙串中。我打字:

git pull https://myuser@bitbucket.org/mypath/myrepo.git

然后控制台问我新密码。

答案 5 :(得分:37)

在@Imran Javed提到的Windows 10中,您可以在以下位置找到通用凭据:

控制面板\所有控制面板项\凭据管理器-> Windows凭据

您的git服务器,然后您可以通过单击“编辑”按钮来更新密码。

enter image description here

答案 6 :(得分:18)

在Windows计算机上,我尝试了@nzrytmn的解决方案,即 控制面板>搜索凭据>在我的用户名对应的git选项类别下选择“ ManageCredentials“>修改后的新凭据。 然后,

已删除当前密码:

git config --global --unset user.password

添加了新密码:

git config --global --add user.password "new_password"

对我有用。

答案 7 :(得分:14)

如果您是MAC用户,则可以从finder中打开KeyChain Access Application,然后查找其中列出的帐户。只需单击它并更新您的密码。 现在试一试,事情就会到位。

链接供参考:Updating your credentials via Keychain Access

为我工作。 :)

答案 8 :(得分:13)

我第一次进入存储库。所以没有定义HEAD

最简单的方法是:

git push -u origin master

然后它将提示输入密码,一旦你输入密码,它将自动保存,你就可以推送。

答案 9 :(得分:9)

如果您使用的是github并启用了2因子身份验证,则需要输入个人访问令牌而不是密码

首先重置密码:

git config --global --unset user.password

然后,登录到您的github帐户,在右上角,单击“设置”,然后单击“开发人员设置”。生成个人访问令牌。复制它。

git push

终端将提示您输入用户名:输入您的电子邮件地址。

在密码提示下,输入个人访问令牌。

答案 10 :(得分:7)

这个问题是如此混乱,因为这个问题太过复杂了。首先是MacOS与Win10。然后是不同的身份验证机制。

我将在此处开始合并的答案,可能需要一些帮助,如果我没有得到帮助,我将继续研究答案,直到完成为止,但这将需要一些时间。

Windows 10: | |-

MacOS: | |-- Using git config to store username and password: | git config --global --add user.password | |---- first time entry | git config --global --add user.password <new_pass> | |---- password update | git config --global --unset user.password | git config --global --add user.password <new_pass> | |-- Using keychain: | git config --global credential.helper osxkeychain | |---- first time entry | Terminal will ask you for the username and password. Just enter it, it will be | stored in keychain from then on. | |---- password update | Open keychain, delete the entry for the repository you are trying to use. | (git remote -v will show you) | On next use of git push or something that needs permissions, git will ask for | the credentials, as it can not find them in the keychain anymore.

答案 11 :(得分:6)

您可以在2个地方通过命令行更改密码,以下操作将编辑凭据以连接存储库

git config --edit 

还可以使用如下所示的全局参数在全局范围内更改凭据

 git config --global --add user.password "XXXX"

或使用

设置凭据帮助器
git config --global credential.helper wincred

但是如果您设置了回购级别凭据,请使用第一个命令

git config --edit

答案 12 :(得分:4)

只需克隆您现有的存储库之一,这将提示您输入新凭据:
例如

git clone https://myuser@bitbucket.org/mypath/myrepo.git

// https://myuser@bitbucket.org/mypath/myrepo.git是您现有存储库之一的地址。

答案 13 :(得分:3)

在 Mac BigSur 11.2.3 上 我更新了 key chain 中的凭据,然后运行了下面的命令。

git credential-osxkeychain erase
host=github.com
protocol=https

我必须这样做,因为在更改为 github 的令牌身份验证后,此线程中没有其他解决方案对我有用。 github 一直说找不到存储库。 如果这不起作用,请尝试将此与此线程中的其他 mac 命令结合使用。

答案 14 :(得分:3)

我可以通过以下方法更改git密码:转到Windows中的凭据管理器,然后删除Windows凭据?通用凭据下的所有git条目。

进行git pull或git push时,Windows会要求输入新用户/密码本身。

答案 15 :(得分:3)

如果您的凭据存储在凭据帮助器中,则删除特定主机的永久密码的便携式方法是致电git credential reject

$ git credential reject
protocol=https
host=bitbucket.org
⏎

$ git credential reject
url=https://bitbucket.org
⏎

然后,要输入新密码,请输入git fetch

答案 16 :(得分:2)

其他答案在 MacOS Big Sur 11.3.1 上都不适合我

我在 Github 上启用了双因素身份验证,这使得即使输入正确的用户名和密码也会失败。

这是我必须做的:

`git config --global --unset user.password`

然后运行您的 git 命令(例如 git push)并输入您的用户名。 对于密码,您需要生成个人访问令牌。

<块引用>

转到 https://github.com/settings/profile 选择右侧的 Developer Settings。选择 Personal Access Token Generate new token。复制生成的令牌并将其用作终端中的密码。

答案 17 :(得分:2)

运行git config --global --unset user.password后跟任何git命令都会提示您输入用户名和密码。

git config --global --unset user.password
git push (will prompt you for the password)
git status (will not prompt for password again)

答案 18 :(得分:2)

尝试了一切,但无济于事。然后,以下方法起作用了。

  1. 在执行上述任何步骤之前,请再次锁定和解锁钥匙串,因为有时卡住了。
  2. 安装GitHub桌面-会有所帮助。

答案 19 :(得分:2)

我会尝试在Keychain Access中删除我的帐户,然后再次运行nav。 Git会问我一个新密码。

答案 20 :(得分:1)

对于那些正在寻找如何重置对存储库访问权限的用户。以GitHub为例。您可以更改您的GitHub配置文件密码,并撤消配置文件的“设置->开发人员设置”中的所有“个人访问令牌”。另外,您可以选择擦除所有SSH / PGP密钥和OAuth / GitHub应用,以确保完全阻止对存储库的访问。因此,任何系统上的所有凭据管理器都将在授权时失败,并提示您输入新的凭据。

答案 21 :(得分:1)

我的密码在github桌面首选项中很好,但是在.git / config文件中错误

对我来说,唯一可行的解​​决方案是手动编辑文件: .git / config

包含以下行: url = https://user:password@github.com/user/repo.git

将密码更改为GOOD密码,因为它对我来说是较旧的密码

答案 22 :(得分:1)

this article中,他们以一种非常简单的方式对其进行了解释,但是基本上,我们只需要执行一个git remote set-url origin "https://<yourUserName>@bitbucket.org/<yourRepo>",下次您执行git pullgit push您将必须输入密码。

答案 23 :(得分:1)

终端内的所有命令行选项都不适合我。最终,我只是手动打开钥匙串,在“所有项目”下搜索“git”,在那里找到一个条目并将其删除。做到了!下次我尝试从终端执行 git pull 时,它提示我输入新凭据。

答案 24 :(得分:0)

如果上述解决方案不起作用,请尝试更改您的删除git网址。

git remote -v

git remote set-url origin

答案 25 :(得分:0)

在终端中执行以下步骤:

  1. 删除保存在Mac中的当前密码

    git config --global --unset user.password
    
  2. 使用此命令添加新密码,替换为新密码:

    git config --global --add user.password <new_pass>
    

答案 26 :(得分:0)

对于MAC用户,使用git GUI(对Sourcetree有用,对其他用户也可能适用)。想要对德里克(https://stackoverflow.com/a/45703718/7138492)的答案加一句话。最初的建议:

$ git config --global --unset user.password

后面应该是推/拉/取 BUT ,如果从GUI完成,则可能不起作用。 %100的工作情况是从控制台执行第一个连续的提示提示符git命令。这是一个示例:

  1. 找到您的git信息库根目录
  2. 输入$ git config --unset user.password
  3. 在终端中选择您喜欢的git命令,例如:$ git push

然后它将要求您提供新密码。

答案 27 :(得分:0)

以下步骤可以解决此问题...

  1. 转到文件夹〜/ Library / Application Support / SourceTree
  2. 删除文件{Username} @ STAuth-bitbucket.org
  3. 重新启动Sourcetree
  4. 尝试获取,出现密码字段,输入新密码
  5. 还可以在终端中运行“ git fetch”命令,并且需要输入密码
  6. 完成

答案 28 :(得分:-1)

只需对您的任何存储库执行 git pull 操作,系统就会提示您输入新密码。