994

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

4
  • 6
    It's probably stored in your OS X keychain (the password store)
    – knittl
    Commented Nov 25, 2013 at 14:17
  • 2
    Could be in your .git/config file, if your username/password are just stored with the git url. Commented Nov 25, 2013 at 14:17
  • 3
    help.github.com/articles/…
    – D.W.
    Commented Jan 3, 2017 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
    Commented Oct 4, 2022 at 21:47

35 Answers 35

1409

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
18
  • 82
    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
    Commented Dec 20, 2016 at 15:15
  • 105
    @b_dubb It might not do anything until the next time you reach out (push, pull,fetch) then you will be prompted for credentials. Commented May 16, 2017 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 below worked for me.
    – neuralmer
    Commented Jul 10, 2017 at 20:14
  • 172
    Does not work on windows. Doesn't prompt for the new password
    – disklosr
    Commented Oct 5, 2017 at 12:18
  • 11
    Just a friendly reminder not to use --global if you have different accounts for different repos
    – nemnesic
    Commented Feb 24, 2020 at 16:11
896

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.

14
  • 1
    This saved me! I was storing it in composer, but it was also creating an auth.json which got annoying because I always forgot to add it to the .gitignore.
    – cbloss793
    Commented Jun 20, 2018 at 18:49
  • 1
    Thankyou that worked ! before then it was prompting me for password but even though I entered new password authincation still failed. Commented Oct 31, 2018 at 13:33
  • 12
    This do nothing for me on Windows. After this command I've tried to push, and it was successful, so the password is still available for git Commented Dec 1, 2018 at 13:21
  • 5
    Worked for me on Win 10. Password prompt popped up and didn't need to go to Control Panel
    – John Lin
    Commented Jan 28, 2019 at 1:36
  • 8
    Worked on Win10. Firstly I used command from this answer and later simply git pull - Windows popup appeared prompting for a password. Thanks!
    – shemekh
    Commented Oct 2, 2019 at 8:57
779

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

16
  • 12
    This was indeed the way. For users that have to work with the Dutch version of the OS: credentials ---> referentiebeheer
    – dexter
    Commented Dec 19, 2018 at 9:08
  • 24
    This was the simplest solution. All you need to do is edit. Thanks.
    – yuva
    Commented May 2, 2019 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
    Commented May 3, 2019 at 13:15
  • 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. Commented Mar 4, 2020 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
    Commented Jan 8, 2021 at 14:34
203

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

4
  • 7
    The question was asked for macOS
    – Saikat
    Commented Jul 13, 2018 at 14:59
  • 26
    @Saikat and yet, many of us with the same question for windows end up finding this SO question. It's almost as if the question itself while tagged macos isn't OS specific!
    – iheanyi
    Commented Dec 21, 2018 at 1:35
  • You can just remove rather than edit, and you'll be prompted on the next push/pull Commented Sep 2, 2020 at 17:32
  • 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
    Commented Jan 30, 2022 at 8:41
133

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://[email protected]/mypath/myrepo.git

Then console asked me for my new password.

4
  • 1
    I tried like this only but still credential pop is displaying, instead of reset password Commented Jan 16, 2017 at 5:28
  • It worked for me, but I had to reset captcha first. Thank you.
    – fiskra
    Commented Nov 8, 2017 at 7:53
  • Worked for me using GitLab. I deleted my access token and generated a new one.
    – mdailey77
    Commented Feb 2, 2023 at 17:29
  • This might be the best way. It accounts for all systems git, not only github, and provides a UI for ease of use. You may or may not need git config --unset user.password.
    – Chris
    Commented Feb 19 at 15:36
114

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

3
  • @halxinate which operating system you use ? This is for windows 10.
    – nzrytmn
    Commented Jan 29, 2019 at 7:27
  • This was the only solution that worked for me on Windows 7
    – tok
    Commented Apr 26, 2021 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
    Commented Jan 30, 2022 at 8:41
67

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
0
54

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.

2
  • 1
    This worked for two-factor authentication scenario. Commented Jun 15, 2021 at 15:35
  • Could you add the source for your quote at the end?
    – Cadoiz
    Commented Nov 9, 2021 at 13:44
51

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

3
  • 1
    This is what worked for me! It allows us to update the password from one repo. Some of the other suggestions on this page will effect everything that git touches. Commented Oct 23, 2018 at 23:18
  • This worked for me as well
    – Eric Aig
    Commented Feb 16, 2022 at 14:51
  • This should be the right answer for mac users, this is how mac manages passwords Commented Feb 17, 2022 at 10:07
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)
2
  • 18
    Well, calling the command git push (or pull) just gave me authentication error and access denied. Did not prompt me Commented Jun 26, 2019 at 12:40
  • This answer doesn't cover anything that isn't covered by Derek's.
    – Bonifacio2
    Commented Aug 20, 2019 at 12:29
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.

3
32

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
    
3
  • 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
    Commented Aug 17, 2021 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. Commented Aug 20, 2021 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://". Commented Nov 25, 2021 at 13:56
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.

6
  • 3
    warning: invalid credential line: ? fatal: unable to read credential from stdin
    – pinei
    Commented Nov 18, 2019 at 20:39
  • 3
    That worked for me under Windows 10, other methods not. This should be probably the correct answer.
    – radzimir
    Commented Jun 22, 2020 at 18:41
  • 2
    Its working in Mac too Commented Feb 21, 2022 at 7:27
  • Indeed, this is the most portable and correct of all answers and should be the main answer to this question. It also worked for me under Linux. Thanks.
    – mfg
    Commented Feb 28, 2022 at 21:59
  • Worked in Linux Mint. Reject the credential and it will ask you to enter the new access token. Commented Aug 19, 2022 at 4:39
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.
`
1
  • 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
    Commented Nov 9, 2021 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.

7
  • if i push from local to my remote server then which password i have to use ? Is this my remote server credential password or other ?
    – Fawwad
    Commented May 30, 2017 at 11:10
  • @Fawwad It's the password for the remote repository. Commented May 30, 2017 at 14:01
  • 3
    My remote server is not github.com. It is my dedicated server where i installed Git.
    – Fawwad
    Commented May 31, 2017 at 11:52
  • i understand how this would help you push the first time, but how this would help to update the saved password.
    – timwaagh
    Commented Jun 22, 2018 at 10:23
  • @Fawwad it doesn't matter what you're using. You still need to give the credentials that provide write access to the repository to which you want to write.
    – iheanyi
    Commented Dec 21, 2018 at 1:39
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.

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>
    
1
  • 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
    Commented Sep 5, 2019 at 8:00
11

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
10

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
0
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:[email protected]/user/repo.git

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

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.

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.

2
  • This is what I chose to do. I had multiple github accounts stored in the Keychain. I chose to delete them all. Successfully pushed my local branch. Commented Oct 7, 2017 at 17:07
  • 1
    not a good answer. Re-cloning is way too much for this simple task Commented Apr 29, 2019 at 15:32
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.

1
5

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

git clone https://[email protected]/mypath/myrepo.git

(where https://[email protected]/mypath/myrepo.git is an address of one of your existing repos)

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.
1
  • How do you do that? Commented Apr 15, 2019 at 6:13
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

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.

1
  • 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
    Commented Jan 31, 2022 at 10:20
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
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.

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.

Not the answer you're looking for? Browse other questions tagged or ask your own question.