如何更新Git的密码?

Ken*_*rty 444 git macos change-password

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

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

Ken*_*rty 736

要在macOS上修复此问题,您可以使用

git config --global credential.helper osxkeychain
Run Code Online (Sandbox Code Playgroud)

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

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

git config --global credential.helper wincred
Run Code Online (Sandbox Code Playgroud)

  • 在Windows上不起作用.不提示输入新密码 (78认同)
  • @b_dubb在你下次伸出(推,拉,提取)之前它可能什么都不做,然后你会被提示输入凭据. (52认同)
  • 在Mac OS 10.12.2上,当我完成上述操作时 - 检查并仔细检查我输入正确 - 没有任何反应. (36认同)
  • 它适用于Mac OS Mojave。谢谢! (7认同)
  • 只是友好提醒,如果您对不同的存储库有不同的帐户,请不要使用“--global” (7认同)
  • @ user2782001我使用的是osxkeychain助手,运行mac命令什么也没做.我怀疑如果有人之前没有使用帮助程序,更改配置以使用帮助程序,则会看到没有为该远程程序输入密码,它会提示,并且第一次一切都会好的.配置的后续更改不会提示.下面的[回答](/sf/answers/2999875721/)为我工作. (2认同)

小智 426

在MacOS Sierra 10.12.4上,没有其他答案对我有用

这是我必须做的:

git config --global --unset user.password
Run Code Online (Sandbox Code Playgroud)

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

  • 这是适合我的方法(在Mac上) (37认同)
  • 曾在Win10上工作过。首先我使用了这个答案中的命令,后来简单地使用了“git pull” - Windows弹出窗口出现提示输入密码。谢谢! (4认同)
  • 在Windows上,这对我没有任何帮助。执行此命令后,我尝试进行推送,并成功完成,因此git仍然可以使用密码 (3认同)
  • 在 Win 10 上为我工作。弹出密码提示,无需进入控制面板 (2认同)

Imr*_*ved 280

在带有Git的Windows 10中

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

在此输入图像描述

  • 这确实是这样的.对于必须使用荷兰语版操作系统的用户:凭证---> referentiebeheer (6认同)
  • 这是最简单的解决方案。您需要做的就是编辑。谢谢。 (5认同)
  • 顺便说一句,对我来说,路径是“控制面板\用户帐户\凭据管理器”,但是最好是键入“凭据”以直接进入。 (2认同)
  • 那是诀窍。谢谢 !Win10是我的操作系统 (2认同)
  • 我在 Windows 上打开任何内容的首选方法是点击 Windows 键并输入该内容的名称,然后在搜索结果中弹出时按 Enter 键。它比建议的通过资源管理器导航更快更容易。 (2认同)

bom*_*om1 148

我可以修改我的git密码的唯一方法是转到Windows中的凭据管理器(Windows密钥+类型'凭据')并编辑Windows凭据通用凭据下的git条目.注意:不按字母顺序列出

  • @Saikat,然而,我们许多对Windows有相同问题的人最终找到了这个SO问题。就像标记的macos一样,问题本身似乎并非特定于操作系统! (8认同)
  • 问题是macOS (5认同)
  • 这是在 Win 10 上对我有用的唯一答案 (2认同)

Jul*_*nez 79

我有同样的问题,并且接受的答案对我没有帮助,因为密码没有存储在钥匙串中.我键入:

git pull https://myuser@bitbucket.org/mypath/myrepo.git
Run Code Online (Sandbox Code Playgroud)

然后控制台问我新密码.


nzr*_*tmn 63

在@Imran Javed上面提到的Windows 10中,您可以在以下位置找到Generic Credentials:

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

对于您的git服务器,然后您可以通过单击编辑按钮更新密码.

在此输入图像描述


And*_*rey 49

对于 Mac

如果您有多个远程存储库(Github、Bitbucket、Job 等)

1)在项目目录下运行

git config --unset user.password
Run Code Online (Sandbox Code Playgroud)

2) 运行远程 git 命令(即 git push 或 git pull)

Git 会提示你为这个仓库重新输入你的用户名和用户密码

或者,如果您只有一个远程存储库可以全局执行此操作

git config --global --unset user.password
Run Code Online (Sandbox Code Playgroud)


Shr*_*thy 27

运行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)
Run Code Online (Sandbox Code Playgroud)

  • 好吧,调用命令git push(或pull)只会给我验证错误,并且访问被拒绝。没有提示我 (7认同)

Nis*_*ant 15

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

链接供参考:通过Keychain Access更新您的凭据

为我工作.:)


小智 15

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

删除当前密码:

git config --global --unset user.password
Run Code Online (Sandbox Code Playgroud)

添加了新密码:

git config --global --add user.password "new_password"
Run Code Online (Sandbox Code Playgroud)

它为我工作。

  • 警告:这会在 ~/.gitconfig 中存储未加密的密码。 (4认同)
  • 不适合我。我已经解决了此处描述的问题:https://cmatskas.com/how-to-update-your-git-credentials-on-windows/ (3认同)

Rap*_*nel 15

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

首先重置密码:

git config --global --unset user.password

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

git push

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

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


use*_*338 14

在这个问题上存在如此混乱,因为这个问题太复杂了。第一个 MacOS 与 Win10。然后是不同的身份验证机制。

我将在这里开始一个统一的答案,可能需要一些帮助,如果我没有得到帮助,我将继续努力直到答案完成,但这需要时间。

视窗 10: |

|-- Run this command. You will be prompted on next push/pull to enter username and password:
|      git config --global credential.helper wincred (Thanks to @Andrew Pye)
Run Code Online (Sandbox Code Playgroud)

` 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.
`
Run Code Online (Sandbox Code Playgroud)


Pri*_*jee 13

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

最简单的方法是:

git push -u origin master
Run Code Online (Sandbox Code Playgroud)

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

  • 我的远程服务器不是github.com.这是我安装Git的专用服务器. (3认同)

小智 13

如果您的凭据存储在凭据帮助程序中,则删除为特定主机保留的密码的便携式方法是调用git credential reject

$ git credential reject
protocol=https
host=bitbucket.org
?
Run Code Online (Sandbox Code Playgroud)

或者

$ git credential reject
url=https://bitbucket.org
?
Run Code Online (Sandbox Code Playgroud)

之后,要输入新密码,请键入git fetch

  • 警告:无效的凭证行:?致命:无法从标准输入读取凭据 (3认同)
  • 这在 Windows 10 下对我有效,其他方法则无效。这应该是正确的答案。 (3认同)
  • 它也可以在 Mac 上运行 (2认同)

Dan*_*ard 11

在 MacOS Big Sur 11.3.1 上没有其他答案对我有用

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

这是我必须做的:

git config --global --unset user.password
Run Code Online (Sandbox Code Playgroud)

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

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


Scr*_*die 11

鉴于 2021 年 8 月 13 日起的新令牌身份验证要求,这可能是您正在寻找的:

  1. 生成新的访问令牌:https : //docs.github.com/en/github/authenticating-to-github/keeping-your-account-and-data-secure/creating-a-personal-access-token
  1. 更新用于访问您的存储库的令牌
git remote remove origin
git remote add origin https://[TOKEN]@github.com/[USER]/[REPO]
git push
Run Code Online (Sandbox Code Playgroud)

  • 这个解决方案对我有用,上面的都没有,我想指定 USER 不是你用来访问你的 github 帐户的用户名,而是 REPO 的用户 (2认同)

Ian*_*amz 9

对于 MacOS,根据自 2021 年 8 月 13 日起使用密码令牌的新规则。

我尝试了所有其他基于终端的答案,但没有一个有效。

  1. 只需前往Keychain Access
  2. 搜索github
  3. 右键单击所有 github 相关项目,包括vs-code
  4. 删除所有项目 在此输入图像描述


小智 8

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

git config --edit 
Run Code Online (Sandbox Code Playgroud)

凭证也可以使用全局参数在全局更改,如下所示

 git config --global --add user.password "XXXX"
Run Code Online (Sandbox Code Playgroud)

或设置凭据助手

git config --global credential.helper wincred
Run Code Online (Sandbox Code Playgroud)

但是如果你有 repo 级别的凭据设置使用第一个命令

git config --edit
Run Code Online (Sandbox Code Playgroud)


Dam*_*tei 8

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

对我来说唯一有效的解决方案是手动编辑文件: .git/config

包含这一行:

url = https://user:password@github.com/user/repo.git
Run Code Online (Sandbox Code Playgroud)

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


Hir*_*iro 6

我会尝试在钥匙串访问中删除我的帐户,然后git clone再次运行。Git 会要求我输入新密码。


Lut*_*man 6

在终端中执行以下步骤:

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

    git config --global --unset user.password
    
    Run Code Online (Sandbox Code Playgroud)
  2. 使用以下命令添加新密码,并替换为新密码:

    git config --global --add user.password <new_pass>
    
    Run Code Online (Sandbox Code Playgroud)

  • 这样,您的密码确实会保存在历史记录中,并且运行history命令的任何人都可以将其视为纯文本。为了防止出现这种情况,您可以在命令前添加一个额外的空间,或者在以后使用正确的行ID运行此命令“ history -d 1234” (2认同)

sha*_*iri 6

我可以通过转到 Windows 中的凭据管理器并删除 Windows 凭据通用凭据下的所有 git 条目来更改我的 git 密码。

在执行 git pull 或 git push 时,windows 会要求输入新的用户/密码本身。


Par*_*esi 5

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

git clone https://myuser@bitbucket.org/mypath/myrepo.git
Run Code Online (Sandbox Code Playgroud)

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


小智 5

在 mac BigSur 11.2.3 上,我更新了钥匙链中的凭据,然后运行了以下命令。

git credential-osxkeychain erase
host=github.com
protocol=https
Run Code Online (Sandbox Code Playgroud)

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