Ken M. Haggerty
Ken M. Haggerty

Reputation: 26168

How do I update the password for Git?

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

Upvotes: 1010

Views: 1563985

Answers (30)

codemania23
codemania23

Reputation: 1071

to update the password, open terminal and just do the following:

  1. run git config --global --unset user.password
  2. run "git pull" and you will be prompted to enter username and password.

Upvotes: 3

Scriddie
Scriddie

Reputation: 3783

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
    

Upvotes: 32

Silent Sojourner
Silent Sojourner

Reputation: 256

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

Upvotes: 0

Imran Javed
Imran Javed

Reputation: 12667

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

Upvotes: 783

cck
cck

Reputation: 532

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

Upvotes: 3

balintn
balintn

Reputation: 1413

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 = [email protected]: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.

Upvotes: 0

Dan Leonard
Dan Leonard

Reputation: 3395

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.

Upvotes: 57

nzrytmn
nzrytmn

Reputation: 6911

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

Upvotes: 114

Derek Lopes
Derek Lopes

Reputation: 9439

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.

Upvotes: 911

user637338
user637338

Reputation: 2665

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

Upvotes: 19

Nishant
Nishant

Reputation: 1044

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

Upvotes: 51

Damien Mattei
Damien Mattei

Reputation: 384

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

Upvotes: 8

emraz
emraz

Reputation: 1613

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

Upvotes: 4

Pardesi_Desi
Pardesi_Desi

Reputation: 2711

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)

Upvotes: 5

Sergey Emeliyanov
Sergey Emeliyanov

Reputation: 6941

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.

Upvotes: 3

Abhimanyu Sharma
Abhimanyu Sharma

Reputation: 443

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.

Upvotes: 38

Ian Samz
Ian Samz

Reputation: 2109

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

Upvotes: 10

Am33d
Am33d

Reputation: 450

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

Upvotes: 0

Bauss
Bauss

Reputation: 51

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.

Upvotes: 5

Cranialsurge
Cranialsurge

Reputation: 95

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.

Upvotes: 4

Andrew
Andrew

Reputation: 37969

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

Upvotes: 69

Raphael Pinel
Raphael Pinel

Reputation: 2780

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.

Upvotes: 16

AnotherYou
AnotherYou

Reputation: 119

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

Upvotes: 11

shaurya airi
shaurya airi

Reputation: 373

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.

Upvotes: 7

Marsu
Marsu

Reputation: 786

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.

Upvotes: 31

Luthfi Rahman
Luthfi Rahman

Reputation: 454

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>
    

Upvotes: 11

Shravan Ramamurthy
Shravan Ramamurthy

Reputation: 4096

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)

Upvotes: 41

chill appreciator
chill appreciator

Reputation: 422

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.

Upvotes: 4

Ken M. Haggerty
Ken M. Haggerty

Reputation: 26168

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

Upvotes: 1428

robertovg
robertovg

Reputation: 1037

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.

Upvotes: 1

Related Questions