balexandre
balexandre

Reputation: 75073

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://[email protected]/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?

I have tried:

in order to unset the password

in order to avoid credentials cache...

Nothing seems to work; does anyone have a better idea?

Upvotes: 1021

Views: 1735617

Answers (30)

Venkataramana Madugula
Venkataramana Madugula

Reputation: 14109

If this problem comes on a Windows machine, do the following.

  • Go to Credential Manager

    • in Czech, it is called: Správce pověření
    • in Dutch, it is called: Referentiebeheer
    • in French, it is called: Gestionnaire d'identification
    • in German, it is called: Anmeldeinformationsverwaltung
    • in Italian, it is called: Gestione credenziali
    • in Norwegian, it is called: Legitimasjonsbehandling
    • in Polish, it is called: Menedżer poświadczeń
    • in Portuguese, it is called: Gerenciador de Credenciais
    • in Russian, it is called: Диспетчер учётных данных
    • in Spanish, it is called: Administrador de credenciales

    Go to Credential Manager

  • Go to Windows Credentials

  • Delete the entries under Generic Credentials

    Go to Windows Credentials and Delete the entries under Generic Credentials

  • Try connecting again. This time, it should prompt you for the correct username and password.

Upvotes: 1335

Vinícius OA
Vinícius OA

Reputation: 357

What worked for me on macos was to delete in keychain access and also .git-credentials

Upvotes: 0

cristianhoyos66
cristianhoyos66

Reputation: 99

As other answers mention this will work for any operative system

rm -rf ~/.git-credentials

Once that is done, any other command related to git remote (pull, push, fetch, etc...) will ask for credentials again and will work as usual.

Upvotes: 1

VonC
VonC

Reputation: 1323045

If git config credential.helper returns manager-core (from the cross-platform GCM -- Git Credential Manager Core project), you can:

  • keep this setting as-is

  • remove your credentials using the cross-platform GCM command:

    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)
(Replace github.com by the actual remote Git repository hosting server: gitlab.com, bitbucket.com, yourOwnServer.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)

At the next git push, enter your credentials as prompter by the GCM-core credential helper: your new credentials will be stored.

Upvotes: 2

kmxr
kmxr

Reputation: 479

On my Win 10, couldn't find Windows Credential Manager nor .git-credentials. What worked was opening Git GUI and pushing the code. It then asked for credentials, which also updated the cached password for my Git Bash.

Upvotes: 0

Alex
Alex

Reputation: 44265

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!

Upvotes: 11

Fares
Fares

Reputation: 667

In our case, clearing the password in the user's .git-credentials file worked.

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

Upvotes: 4

irbanana
irbanana

Reputation: 881

Building from @patthoyts's high-voted answer:

His answer uses but doesn't explain local vs. global vs. system configs. The official git documentation for them is here and worth reading.

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.

My use case is I've got two Github crendentials; 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://[email protected]':
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.

Upvotes: 6

Vikas Chauhan
Vikas Chauhan

Reputation: 1474

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. Enter the details and if you want to store your git credentials, run following command -

git config --global credential.helper store

Upvotes: 5

Maddes
Maddes

Reputation: 361

Update Actually useHttpPath is a git configuration, which should work for all GCMs. Corrected.

Summary of The Original Question

  • working with git on Windows
  • working on multiple repositories on GitHub
  • wrong credentials used for another GitHub repository

Although the title says "Remove credentials", the description leads me to the assumption that you may have multiple accounts on GitHub, e.g. for job-related vs. private projects. (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's GCM for Windows store credentials per host by default. 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). So working with multiple accounts on the same host (here github.com) is not possible by default.

In October 2020 GCM for Windows got deprecated and superseded by GCM Core. The information here still applies to the new GCM and it should even use the credentials stored by GCM for Windows.

Solution

Configure git to include the full path to the repository as additional information for each credential entry. Also documented on 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.

For all possible hosts:

git config --global credential.useHttpPath true

For github.com only:

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.

Upvotes: 5

Suraj Chandgude
Suraj Chandgude

Reputation: 331

For macOS users :

This error appears when you are using multiple Git accounts on the same machine.

Please follow below steps to remove the github.com credentials.

  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

Delete "github.com"

Try again to Push or Pull to git and it will ask for the credentials. Enter valid credentials for repository account. Done, now upvote the answer.

Upvotes: 9

Mohammad Sadoughi
Mohammad Sadoughi

Reputation: 1169

Answer for Mac Devices:

Go to

Applications/Utilities/Keychain Acccess

Search for git.credentials, and delete the git credentials for the desired URL.

Upvotes: 3

Josh
Josh

Reputation: 694

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)

Then remove the remote

$ git remote remove origin

Then add it back

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

Upvotes: 10

Mustkeem K
Mustkeem K

Reputation: 8758

In your project root folder open .git/config. This file has details about remote url and your credentials type.

Your current remote url in this file might be storing credentials. Copy remote url from github and update the url in this config file.

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

Upvotes: 2

Chris F Carroll
Chris F Carroll

Reputation: 12360

Execute the following command in a PowerShell console to clear Git Credentials Managers for Windows cache:

rm $env:LOCALAPPDATA\GitCredentialManager\tenant.cache

or in Cmd.exe

rm %LOCALAPPDATA%\GitCredentialManager\tenant.cache

Upvotes: 3

Marsu
Marsu

Reputation: 786

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:

  • in one line:

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

    $ git credential reject
    protocol=https
    host=gitlab.com
    [email protected]
    • ↵ 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

After that, to enter your new password, type git fetch.

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

Upvotes: 16

nicobo
nicobo

Reputation: 599

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. It's probably not usable as-is as it's quite specific but it shows real life usage of cmdkey.exe.

⚠ This is a shell script run in cygwin

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

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

Upvotes: 4

Trevor
Trevor

Reputation: 1604

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.

I first checked how git was handling my credentials with this command (run git bash with elevated commands or you get errors):

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. 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.

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. 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.

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.

Upvotes: 21

AADProgramming
AADProgramming

Reputation: 6345

For Windows 10, go to below path,

Control Panel\User Accounts\Credential Manager

There will be 2 tabs at this location,

  1. Web credentials and 2. Windows credentials.

Click on Windows credentials tab and here you can see your stored github credentials, under "Generic credentials" heading.

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

Upvotes: 4

patthoyts
patthoyts

Reputation: 33193

The Git credential cache runs a daemon process which caches your credentials in memory and hands them out on demand. 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.

You could also disable use of the Git credential cache using git config --global --unset credential.helper. 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).

On Windows you might be better off using the manager helper (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. With this store, your details are secured by your Windows login and can persist over multiple sessions. 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. A similar helper called winstore is also available online and was used with GitExtensions as it offers a more GUI driven interface. The manager helper offers the same GUI interface as winstore.

Extract from the Windows 10 support page detailing the Windows credential manager:

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.

Upvotes: 784

amitshree
amitshree

Reputation: 2298

If you want git to forget old saved credentials and re-enter username and password, you can do that using below command:

git credential-cache exit

After running above command, if you try to push anything it will provide option to enter username and password.

Upvotes: 22

manish kumar
manish kumar

Reputation: 4692

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.

Upvotes: 3

Jason S
Jason S

Reputation: 189626

On Windows, at least, git remote show [remote-name] will work, e.g.

git remote show origin

Upvotes: 9

Amer Bashoeb
Amer Bashoeb

Reputation: 301

Got same error when doing a 'git pull' and this is how I fixed it.

  1. Change repo to HTTPS
  2. Run command git config --system --unset credential.helper
  3. Run command git config --system --add credential.helper manager
  4. Test command git pull
  5. Enter credentials in the login window that pops up.
  6. Git pull completed successfully.

Upvotes: 18

aaafly
aaafly

Reputation: 3014

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

Upvotes: 216

Pratik Patel
Pratik Patel

Reputation: 2443

This error appears when you are using multiple Git accounts on the same machine.

If you are using macOS then you can remove the saved credentials of github.com.

Please follow below steps to remove the github.com credentials.

  1. Open Keychain Access
  2. Find github
  3. Select the github.com and Right click on it
  4. Delete "github.com"
  5. Try again to Push or Pull to git and it will ask for the credentials.
  6. Enter valid credentials for repository account.
  7. Done

    enter image description here

Upvotes: 46

Akin Okegbile
Akin Okegbile

Reputation: 1176

As Mentioned by Everyone above, This is a Git Credential Manager Issue. 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. A workaround was deleting the remote branch in intellij and re-adding the remote branch. This removes the stored credential and forces refreshing of the credential.

enter image description here

Upvotes: 2

Nick Pirocanac
Nick Pirocanac

Reputation: 151

What finally fixed this for me was to use GitHub desktop, go to repository settings, and remove user:pass@ from the repository url. 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.

GitHub Desktop->Repository->Repository Settings->Remote tab

Change Primary Remote Repository (origin) from:

https://pork@[email protected]/MyProject/MyProject.git

To:

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

Click "Save"

Credentials will be cleared.

Upvotes: 5

Dinesh Patil
Dinesh Patil

Reputation: 1072

  1. Go to C:\Users\<current-user>
  2. check for .git-credentials file
  3. Delete content or modify as per your requirement
  4. Restart your terminal

Upvotes: 17

ChiragBhalgami
ChiragBhalgami

Reputation: 771

You have to update it in your Credential Manager.

Go to Control Panel > User Accounts > Credential Manager > Windows Credentials. You will see Git credentials in the list (e.g. 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.

Upvotes: 38

Related Questions