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

不出意外,我不能再把我的本地提交推到我在BitBucket上的存储库(“https://______.git”认证失败),但我忘记了如何更新iMac上缓存的密码。不知何故,我一直无法在谷歌或Stack Overflow上找到它,尽管在我看来它应该是相当直接的…


当前回答

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

git config --global credential.helper osxkeychain

您的下一个Git操作(拉、克隆、推等)将出现用户名和密码提示。

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

git config --global credential.helper wincred

其他回答

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

删除当前密码:

git config --global --unset user.password

新增新密码:

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

这招对我很管用。

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

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

以下是我必须做的:

Git配置——global——取消设置user.password

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

访问https://github.com/settings/profile,选择右边的开发者设置。Select Personal Access Token生成新的Token。复制生成的令牌,并将其作为终端的密码。

这个问题很混乱,因为这个问题太复杂了。首先是MacOS vs Win10。然后是不同的认证机制。

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

Windows 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)

` MacOS:

|
|-- 1. Using git config to store username and password:
|  git config --global --add user.password
|
|---- 1.1 first time entry
|  git config --global --add user.password <new_pass>
|
|---- 1.2 password update
|  git config --global --unset user.password
|  git config --global --add user.password <new_pass>
|
|-- 2. Using keychain:
|  git config --global credential.helper osxkeychain
|
|---- 2.1 first time entry
|  Terminal will ask you for the username and password. Just enter it, it will be 
|  stored in keychain from then on.
|
|---- 2.2 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.
`

对于Mac

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

1)在项目目录下运行

git config --unset user.password

2)执行远程git命令。Git推还是Git拉)

Git将提示您重新输入user.name和user。此存储库的密码

如果只有一个远程存储库,也可以全局执行

git config --global --unset user.password

运行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)