简体   繁体   English

从 Git 中删除凭据

[英]Remove credentials from Git

I'm working with several repositories, but lately I was just working in our internal one and all was great.我正在使用多个存储库,但最近我只是在我们的内部存储库中工作,一切都很棒。

Today I had to commit and push code into other one, but I'm having some troubles.今天我不得不提交代码并将其推送到另一个代码中,但我遇到了一些麻烦。

$ git push appharbor master
error: The requested URL returned error: 403 while accessing https://gavekortet@appharbor.com/mitivo.git/info/refs?service=git-receive-pack
fatal: HTTP request failed

There is nothing I can do, that would bring the password entry again.我无能为力,那会再次输入密码。

How can I reset the credentials on my system so Git will ask me for the password of that repository?如何重置系统上的凭据,以便 Git 会询问我该存储库的密码?

I have tried:我试过了:

  • git config --global --unset core.askpass

in order to unset the password为了取消密码

  • git config credential.helper 'cache --timeout=1'

in order to avoid credentials cache...为了避免凭据缓存...

Nothing seems to work;似乎没有任何效果; does anyone have a better idea?有没有人有更好的主意?

If this problem comes on a Windows machine, do the following.如果此问题出现在 Windows 计算机上,请执行以下操作。

  • Go to Credential Manager转到凭据管理器

    • in German, it is called: Anmeldeinformationsverwaltung在德语中,它被称为: Anmeldeinformationsverwaltung
    • in French, it is called: Gestionnaire d'identification在法语中,它被称为: Gestionnaire d'identification
    • in Polish, it is called: Menedżer poświadczeń在波兰语中,它被称为: Menedżer poświadczeń
    • in Portuguese, it is called: Gerenciador de Credenciais在葡萄牙语中,它被称为: Gerenciador de Credenciais
    • in Russian, it is called: Диспетчер учётных данных在俄语中,它被称为: Диспетчер учётных данных
    • in Spanish, it is called: Administrador de credenciales在西班牙语中,它被称为: Administrador de credenciales

    转到凭据管理器

  • Go to Windows Credentials转到 Windows 凭据

  • Delete the entries under Generic Credentials删除通用凭据下的条目

    转到 Windows 凭据并删除通用凭据下的条目

  • Try connecting again.再次尝试连接。 This time, it should prompt you for the correct username and password.这一次,它应该提示您输入正确的用户名和密码。

The Git credential cache runs a daemon process which caches your credentials in memory and hands them out on demand. Git 凭证缓存运行一个守护进程,该进程将您的凭证缓存在内存中并按需分发。 So killing your git-credential-cache--daemon process throws all these away and results in re-prompting you for your password if you continue to use this as the cache.helper option.因此,如果您继续使用它作为 cache.helper 选项,那么杀死您的 git-credential-cache--daemon 进程会丢弃所有这些并导致重新提示您输入密码。

You could also disable use of the Git credential cache using git config --global --unset credential.helper .您还可以使用git config --global --unset credential.helper禁用 Git 凭据缓存。 Then reset this, and you would continue to have the cached credentials available for other repositories (if any).然后重置它,您将继续拥有可用于其他存储库(如果有)的缓存凭据。 You may also need to do git config --system --unset credential.helper if this has been set in the system configuration file (for example, Git for Windows 2).如果这已在系统配置文件中设置(例如,Git for Windows 2),您可能还需要执行git config --system --unset credential.helper

On Windows you might be better off using the manager helper ( git config --global credential.helper manager ).在 Windows 上,您最好使用管理器助手( git config --global credential.helper manager )。 This stores your credentials in the Windows credential store which has a Control Panel interface where you can delete or edit your stored credentials.这会将您的凭据存储在 Windows 凭据存储中,该凭据存储具有控制面板界面,您可以在其中删除或编辑存储的凭据。 With this store, your details are secured by your Windows login and can persist over multiple sessions.使用此存储,您的详细信息由您的 Windows 登录名保护,并且可以在多个会话中持续存在。 The manager helper included in Git for Windows 2.x has replaced the earlier wincred helper that was added in Git for Windows 1.8.1.1. Git for Windows 2.x 中包含的管理器帮助程序已经取代了在 Git for Windows 1.8.1.1 中添加的早期wincred帮助程序。 A similar helper called winstore is also available online and was used with GitExtensions as it offers a more GUI driven interface.一个名为winstore的类似帮助程序也可在线获得,并与 GitExtensions 一起使用,因为它提供了更多 GUI 驱动的界面。 The manager helper offers the same GUI interface as winstore .管理器助手提供与winstore相同的 GUI 界面。

Extract from the Windows 10 support page detailing the Windows credential manager:摘自Windows 10 支持页面,详细介绍了 Windows 凭据管理器:

To open Credential Manager, type "credential manager" in the search box on the taskbar and select Credential Manager Control panel .要打开凭据管理器,请在任务栏上的搜索框中键入“凭据管理器”,然后选择凭据管理器控制面板

And then select Windows Credentials to edit (=remove or modify) the stored git credentials for a given URL.然后选择Windows 凭据以编辑(=删除或修改)给定 URL 的存储的 git 凭据。

Retype:重新输入:

$ git config credential.helper store

And then you will be prompted to enter your credentials again.然后系统将提示您再次输入凭据。

WARNING警告

Using this helper will store your passwords unencrypted on disk使用此助手会将您的密码未加密地存储在磁盘上

Source: https://git-scm.com/docs/git-credential-store来源: https : //git-scm.com/docs/git-credential-store

I faced the same issue as the OP.我遇到了与 OP 相同的问题。 It was taking my old Git credentials stored somewhere on the system and I wanted to use Git with my new credentials, so I ran the command它使用存储在系统某处的旧 Git 凭据,我想将 Git 与我的新凭据一起使用,所以我运行了命令

$ git config --system --list

It showed这显示了

credential.helper=manager

Whenever I performed git push it was taking my old username which I set long back, and I wanted to use new a GitHub account to push changes.每当我执行git push ,它都会使用我设置很久的旧用户名,我想使用新的 GitHub 帐户来推送更改。 I later found that my old GitHub account credentials was stored under Control PanelUser AccountsCredential ManagerManage Windows Credentials .后来我发现我的旧 GitHub 帐户凭据存储在Control PanelUser AccountsCredential ManagerManage Windows Credentials 下

管理 Windows 凭据

I just removed these credentials and when I performed git push it asked me for my GitHub credentials, and it worked like a charm.我刚刚删除了这些凭据,当我执行git push它要求我提供我的 GitHub 凭据,它就像一个魅力。

Try using the below command.尝试使用以下命令。

git credential-manager

Here you can get various options to manage your credentials (check the below screen).在这里,您可以获得管理凭据的各种选项(检查以下屏幕)。

在此处输入图片说明

Or you can even directly try this command:或者你甚至可以直接尝试这个命令:

git credential-manager uninstall

This will start prompting for passwords again on each server interaction request.这将在每个服务器交互请求中再次开始提示输入密码。

I found something that worked for me.我找到了对我有用的东西。 When I wrote my comment to the OP I had failed to check the system config file:当我向 OP 写评论时,我未能检查系统配置文件:

git config --system -l

shows a显示一个

credential.helper=!github --credentials

line.线。 I unset it with我用

git config --system --unset credential.helper

and now the credentials are forgotten.现在凭据被遗忘了。

git config --list

will show credential.helper = manager (this is on a windows machine)将显示credential.helper = manager (这是在 Windows 机器上)

To disable this cached username/password for your current local git folder, simply enter要为当前本地 git 文件夹禁用此缓存的用户名/密码,只需输入

git config credential.helper ""

This way, git will prompt for password every time, ignoring what's saved inside "manager".这样,git 每次都会提示输入密码,而忽略“manager”中保存的内容。

In my case, Git is using Windows to store credentials.就我而言,Git 使用 Windows 来存储凭据。

All you have to do is remove the stored credentials stored in your Windows account:您所要做的就是删除存储在您的 Windows 帐户中的凭据:

Windows 凭据菜单

This error appears when you are using multiple Git accounts on the same machine.当您在同一台机器上使用多个 Git 帐户时会出现此错误。

If you are using macOS then you can remove the saved credentials of github.com .如果您使用的是 macOS,那么您可以删除github.com的已保存凭据。

Please follow below steps to remove the github.com credentials.请按照以下步骤删除github.com凭据。

  1. Open Keychain Access打开钥匙串访问
  2. Find githubgithub
  3. Select the github.com and Right click on it选择github.com并右键单击它
  4. Delete "github.com"删除“github.com”
  5. Try again to Push or Pull to git and it will ask for the credentials.再次尝试 Push 或 Pull 到 git,它会要求提供凭据。
  6. Enter valid credentials for repository account.输入存储库帐户的有效凭据。
  7. Done完毕

    在此处输入图片说明

You have to update it in your Credential Manager.您必须在凭据管理器中更新它。

Go to Control Panel > User Accounts > Credential Manager > Windows Credentials.转至控制面板 > 用户帐户 > 凭据管理器 > Windows 凭据。 You will see Git credentials in the list (eg git:https://).您将在列表中看到 Git 凭据(例如 git:https://)。 Click on it, update the password, and execute git pull/push command from your Git bash and it won't throw any more error messages.单击它,更新密码,然后从 Git bash 执行 git pull/push 命令,它不会再抛出任何错误消息。

In Windows 2003 Server with "wincred"*, none of the other answers helped me.在带有“wincred”* 的 Windows 2003 Server 中,其他答案都没有帮助我。 I had to use cmdkey .我不得不使用cmdkey

  • cmdkey /list lists all stored credentials. cmdkey /list列出所有存储的凭据。
  • cmdkey /delete:Target deletes the credential with "Target" name. cmdkey /delete:Target删除名称为“Target”的凭据。

cmd键/列表; cmdkey /delete:目标

(* By "wincred" I mean git config --global credential.helper wincred ) (* 我所说的“wincred”是指git config --global credential.helper wincred

Got same error when doing a 'git pull' and this is how I fixed it.执行“git pull”时遇到同样的错误,这就是我修复它的方式。

  1. Change repo to HTTPS将 repo 更改为 HTTPS
  2. Run command git config --system --unset credential.helper运行命令git config --system --unset credential.helper
  3. Run command git config --system --add credential.helper manager运行命令git config --system --add credential.helper manager
  4. Test command git pull测试命令git pull
  5. Enter credentials in the login window that pops up.在弹出的登录窗口中输入凭据。
  6. Git pull completed successfully. Git pull成功完成。

In caseGit Credential Manager for Windows is used (which current versions usually do):如果使用适用于 Windows 的 Git Credential Manager (当前版本通常会这样做):

git credential-manager clear

This was added mid-2016 .这是在 2016 年中期添加的 To check if credential manager is used:要检查是否使用了凭证管理器:

git config --global credential.helper
→ manager

Using latest version of git for Windows on Windows 10 Professional and I had a similar issue whereby I have two different GitHub accounts and also a Bitbucket account so things got a bit confusing for VS2017, git extensions and git bash.在 Windows 10 Professional 上使用适用于 Windows 的最新版本的 git,我遇到了类似的问题,即我有两个不同的 GitHub 帐户和一个 Bitbucket 帐户,因此对于 VS2017、git 扩展和 git bash,事情有点混乱。

I first checked how git was handling my credentials with this command (run git bash with elevated commands or you get errors):我首先检查了 git 如何使用此命令处理我的凭据(使用提升的命令运行 git bash 否则您会收到错误):

git config --list

I found the entry Credential Manager so I clicked on the START button > typed Credential Manager to and left-clicked on the credential manager yellow safe icon which launched the app.我找到了 Credential Manager 条目,因此我单击了 START 按钮 > 键入 Credential Manager 并左键单击启动该应用程序的凭证管理器黄色安全图标。 I then clicked on the Windows Credentials tabs and found the entry for my current git account which happened to be Bit-bucket so I deleted this account.然后我点击 Windows Credentials 选项卡,找到了我当前 git 帐户的条目,它恰好是 Bit-bucket,所以我删除了这个帐户。

But this didn't do the trick so the next step was to unset the credentials and I did this from the repository directory on my laptop that contains the GitHub project I am trying to push to the remote.但这并没有解决问题,所以下一步是取消设置凭据,我从笔记本电脑上的存储库目录中执行此操作,该目录包含我试图推送到远程的 GitHub 项目。 I typed the following command:我输入了以下命令:

git config --system --unset credential.helper

Then I did a git push and I was prompted for a GitHub username which I entered (the correct one I needed) and then the associated password and everything got pushed correctly.然后我做了一个 git push 并提示我输入一个我输入的 GitHub 用户名(我需要的正确用户名),然后是关联的密码,一切都被正确推送。

I am not sure how much of an issue this is going forward most people probably work off the one repository but I have to work across several and using different providers so may encounter this issue again.我不确定这会带来多大的问题,大多数人可能会在一个存储库中工作,但我必须跨多个并使用不同的提供程序工作,因此可能会再次遇到此问题。

  1. Go to C:\\Users\\<current-user>转到C:\\Users\\<current-user>
  2. check for .git-credentials file检查.git-credentials文件
  3. Delete content or modify as per your requirement根据您的要求删除内容或修改
  4. Restart your terminal重启你的终端

Need to login with respective github username and password需要使用各自的github usernamepassword

To Clear the username and password in windows在windows中清除用户名和密码

Control Panel\\User Accounts\\Credential Manager控制面板\\用户帐户\\凭据管理器

Edit the windows Credential编辑Windows 凭据

Remove the existing user and now go to command prompt write the push command it shows a github pop-up to enter the username / email and password .删除现有用户,现在转到命令提示符编写 push 命令,它显示一个 github 弹出窗口以输入username / emailpassword

Now we able to push the code after switching the user.现在我们可以在切换用户后推送代码。

Remove this line from your .gitconfig file located in the Windows' currently logged-in user folder:从位于 Windows 当前登录的用户文件夹中的 .gitconfig 文件中删除此行:

[credential]
helper = !\"C:/Program Files (x86)/GitExtensions/GitCredentialWinStore/git-credential-winstore.exe\"

This worked for me and now when I push to remote it asks for my password again.这对我有用,现在当我推送到远程时,它再次要求我输入密码。

If you want git to forget old saved credentials and re-enter username and password, you can do that using below command:如果您希望 git 忘记旧的保存凭据并重新输入用户名和密码,您可以使用以下命令执行此操作:

git credential-cache exit

After running above command, if you try to push anything it will provide option to enter username and password.运行上述命令后,如果您尝试推送任何内容,它将提供输入用户名和密码的选项。

If your credentials are stored in the credential helper (generally the case), the portable way to remove a password persisted for a specific host is to call git credential reject :如果您的凭据存储在凭据助手中(通常是这种情况),删除为特定主机保留的密码的便携方法是调用git credential reject

  • in one line:在一行中:

     $ echo "url=https://appharbor.com" | git credential reject
  • or interactively:或交互:

     $ git credential reject protocol=https host=gitlab.com username=me@example.com ↵
    • ↵ is the Enter symbol, just hit Enter key twice at the end of input, don't copy/paste it ↵ 是回车符号,在输入结束时按两次回车键,不要复制/粘贴它
    • The username doesn't seem recognized by wincred, so avoid to filter by username on Windows wincred 似乎无法识别用户名,因此请避免在 Windows 上按用户名进行过滤

After that, to enter your new password, type git fetch .之后,输入你的新密码,输入git fetch

https://git-scm.com/docs/git-credential https://git-scm.com/docs/git-credential

In my case, I couldn't find the credentials saved in the Windows Credential Manager (Windows 7).就我而言,我找不到保存在 Windows 凭据管理器 (Windows 7) 中的凭据。

I was able to reset my credentials by executing我能够通过执行来重置我的凭据

git config --global credential.helper wincred

It was honestly a hail Mary to see if it would wipe out my credentials and it actually worked.老实说,玛丽很高兴看到它是否会抹去我的凭据并且它确实有效。

至少在 Windows 上, git remote show [remote-name]将起作用,例如

git remote show origin

您可以从以下文件C:\\Program Files\\Git\\mingw64\\etc\\gitconfig中删除行credential.helper=!github --credentials以删除 git 的凭据

For macOS users :对于 macOS 用户:

This error appears when you are using multiple Git accounts on the same machine.当您在同一台机器上使用多个 Git 帐户时会出现此错误。

Please follow below steps to remove the github.com credentials.请按照以下步骤删除 github.com 凭据。

  1. Go to Finder转到查找器
  2. Go to Applications转到应用程序
  3. Go to Utilities Folder转到实用程序文件夹
  4. Open Keychain Access打开钥匙串访问
  5. Select the github.com and Right click on it选择 github.com 并右键单击它

Delete "github.com"删除“github.com”

Try again to Push or Pull to git and it will ask for the credentials.再次尝试 Push 或 Pull 到 git,它会要求提供凭据。 Enter valid credentials for repository account.输入存储库帐户的有效凭据。 Done, now upvote the answer.完成,现在赞成答案。

This approach worked for me and should be agnostic of OS.这种方法对我有用,应该与操作系统无关。 It's a little heavy-handed, but was quick and allowed me to reenter credentials.这有点笨手笨脚,但很快,让我重新输入凭据。

Simply find the remote alias for which you wish to reenter credentials.只需找到您希望为其重新输入凭据的远程别名。

$ git remote -v 
origin  https://bitbucket.org/org/~username/your-project.git (fetch)
origin  https://bitbucket.org/org/~username/your-project.git (push)

Copy the project path ( https://bitbucket.org/org/~username/your-project.git )复制项目路径https://bitbucket.org/org/~username/your-project.git

Then remove the remote然后取下遥控器

$ git remote remove origin

Then add it back然后加回来

$ git remote add origin https://bitbucket.org/org/~username/your-project.git

What finally fixed this for me was to use GitHub desktop, go to repository settings, and remove user:pass@ from the repository url.最终为我解决这个问题的是使用 GitHub 桌面,转到存储库设置,然后从存储库 url 中删除 user:pass@。 Then, I attempted a push from the command line and was prompted for login credentials.然后,我尝试从命令行推送并提示输入登录凭据。 After I put those in everything went back to normal.在我把它们放进去之后,一切都恢复了正常。 Both Visual Studio and command line are working, and of course, GitHub desktop. Visual Studio 和命令行都可以使用,当然还有 GitHub 桌面。

GitHub Desktop->Repository->Repository Settings->Remote tab GitHub Desktop->Repository->Repository Settings->Remote 选项卡

Change Primary Remote Repository (origin) from:将主远程存储库(源)从:

https://pork@muffins@github.com/MyProject/MyProject.git https://pork@muffins@github.com/MyProject/MyProject.git

To:到:

https://github.com/MyProject/MyProject.git https://github.com/MyProject/MyProject.git

Click "Save"点击“保存”

Credentials will be cleared.凭据将被清除。

Building from @patthoyts's high-voted answer ( https://stackoverflow.com/a/15382950/4401322 ):根据@patthoyts 的高票答案( https://stackoverflow.com/a/15382950/4401322 )构建:

His answer uses but doesn't explain "local" vs. "global" vs. "system" configs.他的回答使用但没有解释“本地”与“全局”与“系统”配置。 The official git documentation for them is here and worth reading.他们的官方 git 文档在这里,值得一读。

For example, I'm on Linux, and don't use a system config, so I never use a --system flag, but do commonly need to differentiate between --local and --global configs.例如,我在 Linux 上,不使用系统配置,所以我从不使用--system标志,但通常需要区分--local--global配置。

My use case is I've got two Github crendentials;我的用例是我有两个 Github 凭证; one for work, and one for play.一种是工作,一种是娱乐。

Here's how I would handle the problem:这是我将如何处理这个问题:

$ cd work
# do and commit work
$ git push origin develop
# Possibly prompted for credentials if I haven't configured my remotes to automate that. 
# We're assuming that now I've stored my "work" credentials with git's credential helper.

$ cd ~/play 
# do and commit play
$ git push origin develop                                                                   
remote: Permission to whilei/specs.git denied to whilei.                
fatal: unable to access 'https://github.com/workname/specs.git/': The requested URL returned error: 403

# So here's where it goes down:
$ git config --list | grep cred
credential.helper=store # One of these is for _local_
credential.helper=store # And one is for _global_

$ git config --global --unset credential.helper
$ git config --list | grep cred
credential.helper=store # My _local_ config still specifies 'store'
$ git config --unset credential.helper
$ git push origin develop
Username for 'https://github.com': whilei
Password for 'https://whilei@github.com':
Counting objects: 3, done.
Delta compression using up to 12 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 1.10 KiB | 1.10 MiB/s, done.
Total 3 (delta 1), reused 0 (delta 0)
remote: Resolving deltas: 100% (1/1), completed with 1 local object.
To https://github.com/whilei/specs.git
   b2ca528..f64f065  master -> master

# Now let's turn credential-helping back on:
$ git config --global credential.helper "store"
$ git config credential.helper "store"
$ git config --list | grep cred
credential.helper=store # Put it back the way it was.
credential.helper=store

It's also worth noting that there are ways to avoid this problem altogether, for example, you can use ~/.ssh/config 's with associated SSH keys for Github (one for work, one for play) and correspondingly custom-named remote hosts to solve authentication contextualizing too.还值得注意的是,有一些方法可以完全避免这个问题,例如,您可以使用~/.ssh/config与 Github 的关联 SSH 密钥(一个用于工作,一个用于播放)和相应的自定义命名的远程主机也解决身份验证上下文。

For Windows 10, go to below path,对于 Windows 10,请转到以下路径,

Control Panel\\User Accounts\\Credential Manager控制面板\\用户帐户\\凭据管理器

There will be 2 tabs at this location,此位置将有 2 个选项卡,

  1. Web credentials and 2. Windows credentials. Web 凭据和 2. Windows 凭据。

Click on Windows credentials tab and here you can see your stored github credentials, under "Generic credentials" heading.单击 Windows 凭据选项卡,在这里您可以在“通用凭据”标题下看到您存储的 github 凭据。

You can remove those from here and try and re-clone - it will ask for username/password now as we have just removed the stored credential from the Windows 10 systems您可以从这里删除这些并尝试重新克隆 - 现在它会要求输入用户名/密码,因为我们刚刚从 Windows 10 系统中删除了存储的凭据

To add to @ericbn 's https://stackoverflow.com/a/41111629/579827 here are sample commands I've embedded in a script I run to update all my passwords whenever they are renewed.要添加到@ericbn 的https://stackoverflow.com/a/41111629/579827,这里是我嵌入在脚本中的示例命令,我运行的脚本在更新时更新所有密码。 It's probably not usable as-is as it's quite specific but it shows real life usage of cmdkey.exe .它可能无法按原样使用,因为它非常具体,但它显示了cmdkey.exe实际使用情况。

⚠ This is a shell script run in cygwin ⚠ 这是一个在cygwin 中运行的shell脚本 ⚠

⚠ This works because I use private git repos that all authenticate with the same password (you probably don't want to loop over with the same credentials, but you may reuse this sample /list command to extract a list of already registered credentials) ⚠ ⚠ 这是有效的,因为我使用所有使用相同密码进行身份验证的私有 git repos(您可能不想使用相同的凭据循环,但您可以重用此示例/list命令来提取已注册凭据的列表)⚠

entries=`cmdkey.exe /list: | grep git | sed -r -e 's/^[^:]+:\s*(.*)$/\1/gm'`
for entry in ${entries}
do
    cmdkey.exe "/delete:${entry}"
    cmdkey.exe "/generic:${entry}" "/user:${GIT_USERNAME}" "/pass:${GIT_PASSWORD}"
done

Update Actually useHttpPath is a git configuration , which should work for all GCMs.更新实际上useHttpPath是一个git 配置,它应该适用于所有 GCM。 Corrected.更正。

Summary of The Original Question原始问题摘要

  • working with git on Windows在 Windows 上使用 git
  • working on multiple repositories on GitHub在 GitHub 上处理多个存储库
  • wrong credentials used for another GitHub repository用于另一个 GitHub 存储库的错误凭据

Although the title says "Remove credentials", the description leads me to the assumption that you may have multiple accounts on GitHub, eg for job-related vs. private projects.尽管标题是“删除凭据”,但该描述使我假设您可能在 GitHub 上拥有多个帐户,例如用于与工作相关的项目与私人项目。 (At least that issue made me find this topic.) If so read on, otherwise, ignore the answer, but it may come in handy at some time. (至少那个问题让我找到了这个话题。)如果是这样,请继续阅读,否则,忽略答案,但它可能会在某个时候派上用场。

Reason原因

Git Credential Managers (short GCM) like Microsoft'sGCM for Windows store credentials per host by default.默认情况下,Git 凭据管理器(简称 GCM)如 Microsoft 的GCM for Windows存储每个主机的凭据。 This can be verified by checking the Windows Credential Manager (see other answers on how to access it on English, French, and German Windows versions).这可以通过检查 Windows 凭据管理器来验证(请参阅有关如何在英语、法语和德语 Windows 版本上访问它的其他答案)。 So working with multiple accounts on the same host (here github.com) is not possible by default.因此,默认情况下无法在同一主机(此处为 github.com)上使用多个帐户。

In October 2020 GCM for Windows got deprecated and superseded by GCM Core . 2020 年 10 月,GCM for Windows 被GCM Core弃用并取代。 The information here still applies to the new GCM and it should even use the credentials stored by GCM for Windows.这里的信息仍然适用于新的 GCM,它甚至应该使用 GCM for Windows 存储的凭据。

Solution解决方案

Configure git to include the full path to the repository as additional information for each credential entry.配置 git以包含存储库的完整路径作为每个凭证条目的附加信息。 Also documented on GCM for Windows .还记录在GCM for Windows 上
I personally prefer to include the HTTP(S) [repository] path to be able to use a separate account for each and every repository.我个人更喜欢包含 HTTP(S) [repository] ​​路径,以便能够为每个存储库使用单独的帐户。

For all possible hosts:对于所有可能的主机:

git config --global credential.useHttpPath true

For github.com only:仅适用于 github.com:

git config --global credential.github.com.useHttpPath true

Have a look at the GCM and git docs and maybe you want to specify something different.看看 GCM 和git文档,也许你想指定一些不同的东西。

在我们的例子中,清除用户 .git-credentials 文件中的密码对我们有用。

c:\users\[username]\.git-credentials

I'm working with several repositories, but lately I was just working in our internal one and all was great.我正在使用多个存储库,但最近我只是在内部存储库中工作,一切都很棒。

Today I had to commit and push code into other one, but I'm having some troubles.今天,我不得不提交代码并将其推送到其他代码中,但是我遇到了一些麻烦。

$ git push appharbor master
error: The requested URL returned error: 403 while accessing https://gavekortet@appharbor.com/mitivo.git/info/refs?service=git-receive-pack
fatal: HTTP request failed

There is nothing I can do, that would bring the password entry again.我无能为力,这将再次带来密码输入。

How can I reset the credentials on my system so Git will ask me for the password of that repository?如何重置系统上的凭据,以便Git要求我提供该存储库的密码?

I have tried:我试过了:

  • git config --global --unset core.askpass

in order to unset the password为了取消密码

  • git config credential.helper 'cache --timeout=1'

in order to avoid credentials cache...为了避免凭证缓存...

Nothing seems to work;似乎没有任何效果; does anyone have a better idea?有谁有更好的主意吗?

Try this when nothing as mentioned above is working for you.当上面提到的一切都不适合您时,请尝试此操作。

git config credential.helper 'cache --timeout=30'

this will remove the cache every 3sec and will ask for username and password.You can re-run the command with increased timeout values.这将每 3 秒删除一次缓存,并要求输入用户名和密码。您可以使用增加的超时值重新运行该命令。

Answer for Mac Devices : Mac 设备的答案:

Go to

Applications/Utilities/Keychain Acccess

Search for git.credentials , and delete the git credentials for the desired URL.搜索git.credentials ,并删除所需 URL 的 git 凭据。

如果使用密钥对进行了身份验证,则可以删除或移动私钥,或者停止密钥代理并尝试。

As Mentioned by Everyone above, This is a Git Credential Manager Issue. 正如以上每个人所提到的,这是一个Git Credential Manager问题。 Due to permissions, I could not modify my credentials or manipulate the credential manager. 由于权限的原因,我无法修改我的凭证或操纵凭证管理器。 I also could not afford to sit password in plain text on pc. 我也负担不起在PC上以纯文本形式设置密码。 A workaround was deleting the remote branch in intellij and re-adding the remote branch. 解决方法是删除intellij的远程分支,然后重新添加远程分支。 This removes the stored credential and forces refreshing of the credential. 这将删除存储的凭证,并强制刷新凭证。

在此处输入图片说明

In your project root folder open .git/config .在您的项目根文件夹中打开.git/config This file has details about remote url and your credentials type.此文件包含有关远程 url 和您的凭据类型的详细信息。

Your current remote url in this file might be storing credentials.您当前在此文件中的远程 url 可能正在存储凭据。 Copy remote url from github and update the url in this config file.从 github 复制远程 url 并更新此配置文件中的 url。

Like below:像下面这样:

[remote "origin"]
    url = [update it]
    fetch = +refs/heads/*:refs/remotes/origin/*
[credential]
    helper = manager

Now when you try to push your code it will ask for credentials.现在,当您尝试推送代码时,它会要求提供凭据。 Thanks谢谢

Kindly run following command -请运行以下命令 -

git config --global credential.helper cache

and then run any git command like git pull it will ask for username and password.然后运行任何 git 命令,比如 git pull 它会要求输入用户名和密码。 Enter the details and if you want to store your git credentials, run following command -输入详细信息,如果要存储 git 凭据,请运行以下命令 -

git config --global credential.helper store

If git config credential.helper returns manager-core (from the corss-platform GCM -- Git Credential Manager Core ), you can:如果git config credential.helper返回manager-core (来自 corss-platform GCM -- Git Credential Manager Core ),您可以:

  • keep this setting as-is保持这个设置不变

  • remove your credentials using the cross-platform GCM command:使用跨平台 GCM 命令删除您的凭据:

     printf "Host=github.com\\nusername=xxx\\nprotocol=https" | \\ git credential-manager-core erase

Check it is gone with:检查它是否消失了:

  printf "Host=github.com\nusername=xxx\nprotocol=https" | \
    git credential-manager-core get

(Replace xxx by your GitHub user account name) (用你的 GitHub 用户名替换xxx
(Replace github.com by the actual remote Git repository hosting server: gitlab.com , bitbucket.com , yourOwnServer.com ) (将github.com替换为实际的远程 Git 存储库托管服务器: gitlab.combitbucket.comyourOwnServer.com

If you see a prompt for your credentials, click "Cancel": the previous credentials are gone from the OS underlying secret manager (Windows Credential Manager, Linux libsecret or Mac osxkeychain)如果您看到输入凭据的提示,请单击“取消”:以前的凭据已从操作系统底层机密管理器(Windows 凭据管理器、Linux libsecret 或 Mac osxkeychain)中消失

At the next git push, enter your credentials as prompter by the GCM-core credential helper: your new credentials will be stored.在下一次 git push 时,通过 GCM-core 凭证助手输入您的凭证作为提示:您的新凭证将被存储。

No answer given worked for me.没有给出的答案对我有用。 But here is what worked for me in the end:但最终对我有用的是:

rm -rf ~/.git-credentials

That will remove any credentials!这将删除任何凭据! When you use a new git command, you will be asked for a password!当你使用一个新的git命令时,你会被要求输入密码!

On my Win 10, couldn't find Windows Credential Manager nor .git-credentials .在我的 Win 10 上,找不到 Windows Credential Manager.git-credentials What worked was opening Git GUI and pushing the code.起作用的是打开 Git GUI 并推送代码。 It then asked for credentials, which also updated the cached password for my Git Bash.然后它要求提供凭据,这也更新了我的 Git Bash 的缓存密码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM