956

I'm using BitBucket with Xcode and Git for version control, and recently I changed all of my passwords (thanks Adobe!).

Unsurprisingly, I'm no longer able to push my local commits to my repository on BitBucket (Authentication failed for 'https://______.git'), but I'm forgetting how to update the cached password on my iMac. Somehow I've been unable to find it on Google or Stack Overflow, though it seems to me it should be rather straightforward...

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Ken M. Haggerty
  • 24,902
  • 5
  • 28
  • 37
  • 6
    It's probably stored in your OS X _keychain_ (the password store) – knittl Nov 25 '13 at 14:17
  • 2
    Could be in your .git/config file, if your username/password are just stored with the git url. – Erik Kerber Nov 25 '13 at 14:17
  • 3
    https://help.github.com/articles/updating-credentials-from-the-osx-keychain/ – D.W. Jan 03 '17 at 23:41
  • If you are on macOS and nothing else works, try updating "Internet Password" github.com entry in Keychain Access app. Then set the new Personal Access Token (PAT) as password. – gusa Oct 04 '22 at 21:47

34 Answers34

1358

To fix this on macOS, you can use

git config --global credential.helper osxkeychain

A username and password prompt will appear with your next Git action (pull, clone, push, etc.).

For Windows, it's the same command with a different argument:

git config --global credential.helper wincred
Paul Solt
  • 8,375
  • 5
  • 41
  • 46
Ken M. Haggerty
  • 24,902
  • 5
  • 28
  • 37
  • 79
    On Mac OS 10.12.2 and when I did the above - checked and double checked that I entered it correctly - and nothing happened. – b_dubb Dec 20 '16 at 15:15
  • Worked for me just now on 10.12.3 (Sierra). Had to do it twice though but that may have been a VPN/network issue – rkd May 04 '17 at 23:17
  • 101
    @b_dubb It might not do anything until the next time you reach out (push, pull,fetch) then you will be prompted for credentials. – user2782001 May 16 '17 at 17:31
  • 7
    @user2782001 I was using the osxkeychain helper, running the mac command did nothing. I suspect that if someone was not using the helper before, changing the configuration to use the helper, it would see that a password had not been entered for that remote, it would prompt, and everything would be fine the first time. Subsequent changes of the configuration would not prompt. The [answer](https://stackoverflow.com/a/42855367/6251951) below worked for me. – neuralmer Jul 10 '17 at 20:14
  • 172
    Does not work on windows. Doesn't prompt for the new password – disklosr Oct 05 '17 at 12:18
  • Worked perfectly on Sierra. So silly that it doesn't just ask you to re-login. It just fails with a `remote: Invalid username or password.` – phocks Oct 19 '17 at 01:49
  • This only worked for me (on sierra) up to the point where it began asking me for un/pw ... but it refuses to accept what I have demonstrated to myself over and over again to be the correct password. I do have two-factor enabled, so I have to assume it is involved, but I'm not being prompted for anything related to that. – Joshua Eric Turcotte Nov 02 '17 at 13:58
  • 1
    @JoshuaEricTurcotte I know this is way late, but if you have two factor enabled you need to generate an API token from your account settings in GitHub and use that for your password. Instructions here: https://help.github.com/articles/creating-a-personal-access-token-for-the-command-line/ – Michael Aug 21 '18 at 14:02
  • Did not work for me on macOS Sierra 10.12.6. git version 2.8.4 – Daniel Diehl Aug 31 '18 at 19:23
  • This does not seem to do anything. OSX El Capitan. git version 2.7.4 – bgenchel Sep 02 '18 at 00:53
  • There is no visible immediate feedback, but it works on High Sierra. I had to clone a github repository before it actually asks for the password, it seems like it just sets a "dirty" flag for the next time you do a github request as @user2782001 mentioned. – Paul Solt Nov 29 '18 at 15:23
  • For me the symptoms were showing like `remote: repository not found` just after I changed my Github user password on MacOS Mojave, I just followed the steps outlined here https://help.github.com/en/articles/updating-credentials-from-the-osx-keychain. Great help. – codarrior May 09 '19 at 02:26
  • 11
    Just a friendly reminder not to use `--global` if you have different accounts for different repos – nemnesic Feb 24 '20 at 16:11
  • Thanks for this! Worked perfectly on Windows 10 using mingw64. – f1v3 Dec 10 '20 at 08:13
  • I ran command for Mac on Windows machine. It did not recognize the command but a popup opened to enter password, which I was looking for. – yılmaz Sep 01 '21 at 07:43
  • Windows solution worked for me (win10). – Arash Kamangir Feb 09 '22 at 12:07
  • For mac you could try https://stackoverflow.com/a/67765064/1110305 – Chamila Adhikarinayake Jul 15 '22 at 07:23
  • on windows, you might be using system and not global, so then use `git config --system credential.helper wincred` instead – ericosg Jul 21 '22 at 07:43
862

None of the other answers worked for me on MacOS Sierra 10.12.4

Here is what I had to do:

git config --global --unset user.password

Then run your git command (ex. git push) and reenter your username and password.

Cadoiz
  • 1,446
  • 21
  • 31
Derek Lopes
  • 8,949
  • 1
  • 11
  • 7
773

In Windows 10 with Git

Remove/update related Credentials stored in Windows Credentials in >>Control Panel\All Control Panel Items\Credential Manager

Or you can just use the search bar and search for "CredentialManager" or "Windows Credentials", which should return an entry to open that Control Panel pane (at least for English users).

enter image description here

starball
  • 20,030
  • 7
  • 43
  • 238
Imran Javed
  • 11,779
  • 2
  • 16
  • 17
  • 12
    This was indeed the way. For users that have to work with the Dutch version of the OS: credentials ---> referentiebeheer – dexter Dec 19 '18 at 09:08
  • 23
    This was the simplest solution. All you need to do is edit. Thanks. – yuva May 02 '19 at 16:00
  • 8
    Btw, the path for me was Control Panel\User Accounts\Credential Manager but best is to type Credential to jump right in. – Everts May 03 '19 at 13:15
  • @Everts what is OS of your machine? – Imran Javed May 06 '19 at 16:50
  • 2
    My preferred method for opening anything on Windows, is to tap the Windows key and type the name of the thing in, and then press enter when it pops up in the search results. It's a lot faster and easier than navigating through explorer as suggested. – carlin.scott Mar 04 '20 at 22:20
  • 1
    Thanks! I'm using git-fork and had to delete all credentials to our on-premise Azure Dev Ops server after Windows wanted me to change my domain password. Thereafter git push magically worked again without entering new credentials. Simply editing those credentials did not work. – ZuBsPaCe Jan 08 '21 at 14:34
  • @ZuBsPaCe, some times you have to close related program (git, vs or etc) to get fresh data – Imran Javed Feb 01 '21 at 12:54
  • 1
    My credentials disappeared from here somehow, so I ran `git fetch` in one of my repos. Windows propmpted for authentication, and then populated the credentials here as expected. – Reed Feb 24 '21 at 14:45
  • 1
    It worked for windows 7 too (don't ask why our company is using ancient Windows) – Positive Navid May 21 '21 at 11:24
  • 1
    If you wanna add one credential, the Internet or network address should be something like `git:https://yourrepo.address`, then your username and pass for it. – Takatalvi Oct 19 '21 at 18:47
  • 1
    There is no git related generic credentials on my computer while I use git commit, push, pull everyday. Then how can we update the password? Please suggest. Thanks. – Kamlesh Jan 30 '22 at 08:41
  • @Kamlesh, hope it is a case of credentials at repo instead of Global. If this is the case then it will ask you to reenter credentials in case of failure or you can change it through command directly. you can try >git credential reject – Imran Javed Feb 02 '22 at 21:04
  • @ImranJaved Thanks for your reply. You can check my issue at https://stackoverflow.com/questions/70913288/how-to-change-github-password-by-command-line-on-windows-mac – Kamlesh Feb 03 '22 at 16:48
  • @Kamlesh, if you are stuck and there is no pending pull or push then I will recommend to refresh you repo clone. – Imran Javed Feb 08 '22 at 17:18
  • @ImranJaved git pull / push / merge / commit all are working. But due to compromised my command line password, I want to change it. Not found any solution yet. Thanks a lot. – Kamlesh Feb 09 '22 at 13:22
  • 1
    In German Windows the Credential Manager is called "Anmeldeinformationsverwaltung" – grefel May 13 '22 at 11:17
202

The only way I could modify my git password was to go to Credential Manager in Windows (Windows Key + type 'credential') and edit the git entry under Windows Credentials Generic Credentials. Note: Not listed alphabetically

bom1
  • 2,173
  • 1
  • 12
  • 6
126

I had the same problem, and the accepted answer didn't help me because the password wasn't stored in the keychain. I typed:

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

Then console asked me for my new password.

Julián Martínez
  • 3,054
  • 3
  • 19
  • 17
113

In windows 10 as mentioned above by @Imran Javed you can find Generic Credentials at :

Control Panel\All Control Panel Items\Credential Manager --> Windows Credentials

find your git server and than you can update password by clicking edit button.

enter image description here

nzrytmn
  • 6,193
  • 1
  • 41
  • 38
  • @halxinate which operating system you use ? This is for windows 10. – nzrytmn Jan 29 '19 at 07:27
  • This was the only solution that worked for me on Windows 7 – tok Apr 26 '21 at 10:24
  • There is no git related generic credentials on my computer while I use git commit, push, pull everyday. Then how can we update the password? Please suggest. Thanks. – Kamlesh Jan 30 '22 at 08:41
65

For Mac

If you have multiple remote repositories (Github, Bitbucket, Job, etc.)

1) run in the project directory

git config --unset user.password

2) run remote git command (ie. git push or git pull)

Git will prompt you to reenter your user.name and user.password for this repository

Or you can do it globally if you have only one remote repository

git config --global --unset user.password
Andrew
  • 36,676
  • 11
  • 141
  • 113
52

None of the other answers worked for me on MacOS Big Sur 11.3.1

I had Two-Factor Authentication enabled on Github, this makes is so you will fail when entering your username and password even when they are correct.

Here is what I had to do:

git config --global --unset user.password

Then run your git command (ex. git push) and enter your username. For the password you need to generate a Personal Access Token.

Go to https://github.com/settings/profile select the Developer Settings on the right. Select Personal Access Token Generate new token. Copy the generated token and use it as the password in terminal.

Dan Leonard
  • 3,325
  • 1
  • 20
  • 32
50

If you are MAC user then you can open KeyChain Access Application from finder and then look for your account listed there. Just click on it and update your password. Now give a try and things will fall in place.

link for reference: Updating your credentials via Keychain Access

Cadoiz
  • 1,446
  • 21
  • 31
Nishant
  • 1,034
  • 9
  • 19
41

running git config --global --unset user.password followed by any git command would prompt you to enter username and password.

git config --global --unset user.password
git push (will prompt you for the password)
git status (will not prompt for password again)
Shravan Ramamurthy
  • 3,896
  • 5
  • 30
  • 44
36

In my Windows machine, I tried the solution of @nzrytmn i.e., Control Panel>Search Credentials>Select "ManageCredentials">modified new credentials under git option category corresponding to my username. And then,

Deleted current password:

git config --global --unset user.password

Added new password:

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

And It worked for me.

Cadoiz
  • 1,446
  • 21
  • 31
31

If your credentials are stored in the credential helper, the portable way to remove a password persisted for a specific host is to call git credential reject:

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

or

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

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

Marsu
  • 786
  • 6
  • 9
28

Token authentication

Given the new token authentication requirement from August 13 2021, this may be what you are looking for:

  1. Generate a new access token
  2. Update the token used to access your repository:
    git remote remove origin
    git remote add origin https://[TOKEN]@github.com/[USER]/[REPOSITORY]
    git push
    
Scriddie
  • 2,584
  • 1
  • 10
  • 17
  • 2
    This solution worked for me, none of those above did, I want to specify that USER is not the username that u use to access to ur github account, but the user of REPO – Hanane Aug 17 '21 at 15:56
  • Yes. This is the only solution that worked for me. One command one should run first is: ```git remote -v``` so that one can see the existing [USER] and [REPO] parameters. – Neil Fraser Aug 20 '21 at 17:52
  • If the name of your personal access token is "token" and token value is "123" then [TOKEN] = token:123 . For github.com/[USER]/[REPO], copy the URL that points at your repository - everything after "https://". – Ian Warburton Nov 25 '21 at 13:56
  • Thanks man, you saved me a lot of time. – Mohammed Saber Mohammed Jun 05 '23 at 02:37
19

There is such a confusion on this question, as there is way too much complexity in this question. First MacOS vs. Win10. Then the different auth mechanisms.

I will start a consolidated answer here and probably need some help, if I do not get help, I will keep working on the answer until it is complete, but that will take time.

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.
`
user637338
  • 2,565
  • 1
  • 25
  • 26
  • I updated your formatting tried to add the reference to **Andrew Pye**, but couldn't find something. Reformatting Renhuais comment: running `git config --global --unset user.password` and then `git push origin master` will ask you for username and password. Put that into the answer too? – Bazer Con Nov 09 '21 at 14:14
18

I was pushing into the repository for the first time. So there was no HEAD defined.

The easiest way would be to:

git push -u origin master

It will then prompt for the password, and once you enter that it will be saved automatically, and you will be able to push.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Pritam Banerjee
  • 17,953
  • 10
  • 93
  • 108
16

If you are using github and have enabled 2 factor authentication, you need to enter a Personal access token instead of your password

First reset your password:

git config --global --unset user.password

Then, log to your github account, on the right hand corner, click on Settings, then Developer Settings. Generate a Personal access token. Copy it.

git push

The terminal will prompt you for your username: enter your email address.

At the password prompt, enter the personal access token instead.

Raphael Pinel
  • 2,352
  • 24
  • 26
11

do these steps in Terminal:

  1. Delete current password saved in your Mac

    git config --global --unset user.password
    
  2. Add your new password by using this command, replace with your new password:

    git config --global --add user.password <new_pass>
    
Luthfi Rahman
  • 424
  • 6
  • 17
  • 4
    This way your password does get saved in history, and anyone who runs the history command can see it as plain text. To prevent it you can add an extra space before the command or run this command 'history -d 1234' with the right line ID afterwards – Lavandysh Sep 05 '19 at 08:00
10

you can change password through command line in 2 places, following would edit credentials to connect the repo

git config --edit 

The credentials also can be changed at global using global parameter like below

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

or set the credentials helper with

git config --global credential.helper wincred

but if you have repo level credentials set the use the first command

git config --edit
AnotherYou
  • 109
  • 1
  • 3
9

For MacOS based on the new rule to use password tokens from August 13 2021.

I tried all other terminal based answers but none worked.

  1. Simply head to Keychain Access
  2. Search for github
  3. Right click on all github related items, including vs-code,
  4. Delete all items enter image description here
Ian Samz
  • 1,743
  • 20
  • 20
8

my password was good in github desktop preferences but wrong in the .git/config file

for me the only working solution was to manually edit the file: .git/config

that contains this line:

url = https://user:password@github.com/user/repo.git

change password to the GOOD password because it was an older one for me

Damien Mattei
  • 358
  • 4
  • 9
7

I was able to change my git password by going to Credential Manager in Windows and deleting all the git entries under Windows Credentials Generic Credentials.

When doing a git pull or git push, windows will ask for the new user/password itself.

shaurya airi
  • 375
  • 4
  • 6
6

I would try to delete my account in Keychain Access and then run git clone again. Git will ask me for a new password.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Hiro
  • 391
  • 5
  • 10
5

Just clone one of your existing repos, this will prompt you for new credentials:
e.g.

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

(where https://myuser@bitbucket.org/mypath/myrepo.git is an address of one of your existing repos)

Pardesi_Desi
  • 2,521
  • 1
  • 12
  • 8
5

on mac BigSur 11.2.3 I updated the credentials in the key chain then I ran the command below.

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

I had to do this because no other solution in this thread worked for me after changing to token auth for github. github kept stating repository not found. If this does not work try to combine this with the other commands for mac in this thread.

Bauss
  • 51
  • 1
  • 3
  • Exactly what I was looking for. Source for this is: https://docs.github.com/en/get-started/getting-started-with-git/updating-credentials-from-the-macos-keychain – Sam Soffes Dec 16 '21 at 02:46
4

Tried everything but nothing worked. Then the following did work.

  1. Before any of the above steps, lock and unlock the keychain again coz sometimes it sorta gets stuck.
  2. Install the GitHub Desktop — it helps.
4

For those who are looking for how to reset access to the repository. By the example of GitHub. You can change your GitHub profile password and revoke all "Personal access tokens" in "Settings -> Developer settings" of your profile. Also you can optionally wipe all your SSH/PGP keys and OAuth/GitHub apps to be sure that access to the repository is completely blocked. Thus, all the credential managers, on any system will fail at authorisation and prompt you to enter the new credentials.

4

Following steps can resolve the issue .....

  1. Go to the folder ~/Library/Application Support/SourceTree
  2. Delete the file {Username}@STAuth-bitbucket.org
  3. Restart Sourcetree
  4. Try to fetch, password filed appear, give your new password
  5. Also can run git fetch command in terminal and need to type password
  6. Done
emraz
  • 1,563
  • 20
  • 28
3

None of the command line options from within terminal worked for me. Ultimately, I just opened up keychain manually, searched for 'git' under 'All Items', found an entry there and deleted it. That did it! Next time I tried a git pull from the terminal and it prompted me for new creds.

Cranialsurge
  • 85
  • 1
  • 6
  • In Visual Studio Code, the terminal command's did not do anything for me. Opening KeychainAccess (not Keychain) searching and deleting the entry fixed the problem. When using BitBucket, search for bitbucket instead of git. – Gert Jan 31 '22 at 10:20
3

On macOS, e.g. after OSX v.11.6, should go to KeyChain and search "git". And delete the relevant keys. It will work.

cck
  • 502
  • 4
  • 17
2

For MAC users, using git GUI (Works for Sourcetree, may work for others as well). Would like to add a small remark to Derek's answer. The original suggestion:

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

should be followed by a push/pull/fetch BUT it might not work when done from the GUI. The %100 working case would be to do the very first consecutive prompt-triggering git command from console. Here is an example:

  1. Locate to your git repository root directory
  2. Type in $ git config --unset user.password
  3. Proceed with a git commend of your choice in terminal e.g.: $ git push

Then it will ask you to provide the new passoword.

Sergey Emeliyanov
  • 5,158
  • 6
  • 29
  • 52
1

In this article, they explain it in a very easy way but basically, we just need to execute a git remote set-url origin "https://<yourUserName>@bitbucket.org/<yourRepo>" and next time you do a git pull or a git push you will have to put your password.

Alhamza Alnaimi
  • 97
  • 2
  • 2
  • 11
robertovg
  • 1,018
  • 11
  • 16
0

Just do a git pull of any of your repository and you will be prompted to enter your new password.

Am33d
  • 413
  • 1
  • 4
  • 14
0

I had the same issue (on Windows 10, Git version 2.34.1.windows.1, using Personal Access Token with SAML SSO enabled by my org): when I issued git pull in my repo, I received the error message

ERROR: The `xxx' organization has enabled or enforced SAML SSO. To access this repository, you must use the HTTPS remote with a personal access token or SSH with an SSH key and passphrase that has been authorized for this organization. Visit https://docs.github.com/articles/authenticating-to-a-github-organization-with-saml-single-sign-on/ for more information. fatal: Could not read from remote repository.

I found that in my .git/config file I had this: url = git@github.com:myorg/myrepo.git

The link in the error message above stats to use SAML SSO (Personal Access Token, PAT) so I changed it to url = https://www.github.com/myorg/myrepo.git

This time when issuing a git command like git pull I was presented with a login dialog where I could provide my PAT token and it started to work.

balintn
  • 988
  • 1
  • 9
  • 19
0

I use the git extension on Visual Studio Code to access my company's git repo on Windows Azure. Originally I used command below to login:

git remote set-url origin https://username:password@dev.azure.com/foo

After my password expired, I couldn't find my credential in the Windows Credential Manager. So I removed remote in the REMOTES section of VS Code, then added it back. When I clicked the Fetch button and it prompted me to choose a Windows credential. I chose the one I used to login to Windows and it connected to git repo successfully. I then also found the credential in the Windows Credential Manager.