125

After I changed my GitHub password, I am unable to push to the remote:

$ git push origin master
remote: Invalid username or password.

Is there only re clone the repository?

Ciro Santilli OurBigBook.com
  • 347,512
  • 102
  • 1,199
  • 985
kenu.heo
  • 1,469
  • 2
  • 14
  • 20
  • Just remove and add the remote again – onmyway133 Aug 01 '16 at 09:43
  • 1
    Really? "Just remove and add the remote again"? Starting from scratch is inconvenient and error-prone in some operations. – Jason S Nov 25 '16 at 22:25
  • 1
    This can also happen after enabling two-factor authentication, in this case you should follow the instruction here: https://stackoverflow.com/a/34919582/2898283 – mechatroner Oct 07 '17 at 07:16
  • @JasonS Re-adding a remote is hardly "starting from scratch." This would only modify the local copies of remote branches, which you don't modify directly anyway; all local branches would remain intact, although I'm not sure if tracking would be affected. – jpmc26 Jun 05 '19 at 11:08
  • @jpmc26 I don't mean the repository content, I mean re-adding the URL. – Jason S Jun 05 '19 at 22:56

11 Answers11

205

If you had your remote's password changed only, not the username, then try the following command to check remote's info:-

git remote show origin

This will ask for your password for the given git user, fill that in correctly, and now try:-

git pull

or,

git push

It should work unless you have to change other things like username or remote URL, you can take a look at the following Git documentation:-

https://help.github.com/articles/setting-your-username-in-git/

https://help.github.com/articles/changing-a-remote-s-url/

Community
  • 1
  • 1
Amit
  • 2,255
  • 1
  • 11
  • 8
  • 12
    It works for me. `git remote show origin` shows prompt – Lazaro Fernandes Lima Suleiman Oct 31 '16 at 13:17
  • 14
    Interesting - `git remote show origin` didn't prompt me, it just `show`-ed me, so I thought it failed (at what I needed it to do). But, just in case, I then tried `git push origin master` and *that* prompted me. So... I still got where I needed to be :) – dwanderson Feb 01 '17 at 22:24
  • 1
    Tried this with IntelliJ and Android Studio, and both didn't work without restart, probably because credentials are cached. I edited the answer to reflect this. – Oliver Hausler May 10 '17 at 02:37
  • 2
    Worked just as described for me. – nabrown Jun 10 '17 at 03:40
  • 2
    Worked as expected on Mac. Should be accepted answer. – Aakanksha Aug 10 '17 at 12:11
  • 1
    I recently changed my GitHub username and got this same problem. After removing the old account, connecting it again, creating a new ssh key set, and then finally using your suggestion I'm able to push to the repo. Thank you so much, I've been screwing with this for hours. – Doug Watkins Feb 01 '18 at 20:26
  • 1
    This also worked for me in the context of my company git repository. – Thomas Mar 08 '18 at 15:50
45

To update the password in your Terminal. Try the below command, It will prompt you password again.

git push -u origin master
hiddenpearls
  • 663
  • 6
  • 12
38

The OP kenu.heo has worked around the issue by removing, then re-cloning the repo.

But for other:

It depends on your OS, git version and protocol you are using.

Depending on the OS, you have ways to cache your credentials (OSX KeyChain on Mac, netrc credential helper on Windows or Linux), and that could explain why your push isn't working after changing your GitHub password.
For a keychain, you would need to reset that password stored in it.

That password issue also suggest that you are using an https url (not an ssh one, which would depends on public/private ssh keys, and wouldn't be influenced by a GitHub account password, since the public SSH key registered to your GitHub account wouldn't have changed).

Check that with a git remote -v.

You can force git to use your GitHub login with a:

git remote set-url origin https://Username@github.com/Username/MyRepo.git

(replace 'Username' and 'MyRepo.git' by your own values)

Then try again to push, it should ask for your GitHub password. Enter the new one.

If this doesn't work, check if you have activated the 2FA (2-Form Authentication). If that is the case, you need to generate a PTA (Personal Token Access).
See more at "Configure Git clients, like GitHub for Windows, to not ask for authentication".

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
33

On a Windows System none of the steps worked for me, the problem is that the credentials are stored in Windows Credentials Manager.

You can go to Control Panel -> User Accounts -> Credential Manager -> Windows Credentials

Under Generic Credentials you will find your git Url, expand the selection and click on edit.

Once edited just trigger a git push again and it should work.

Source of information :- Remove credentials from Git

Sap
  • 331
  • 3
  • 2
17

From what I've experienced, you just need to re-enter the remote-addr.

And git will ask usr/password for the new one rather than keeping silent and use the deprecated one.

see your remotes, locate which one you want to change

>git remote  
github
gitcafe
company

for example, if you changed your company repo password, you can do:

>git remote remove company

This won't touch your folder, won't touch your commits. This just delete a url-string from git

Then, add this url again:

>git remote add company https://git.AyCramba.com/xxx.git

Push to it:

>git push company master
username for 'https://git.AyCramba.com':
password for 'https://git.AyCramba.com':

Then it starts pushing

Hope it helps.

Chiron
  • 974
  • 1
  • 8
  • 20
  • 1
    The `git remote set-url` I mention [in my answer](http://stackoverflow.com/a/21747457/6309) does a remove+add. – VonC Jan 12 '16 at 05:43
3

The username and password may be stored in Windows Credential Manger. Check and update there, if necessary.

(I know that's a bit obvious and simple, but might help some people.)

msq
  • 146
  • 7
3

You can update the Username and password by this command:

$ git remote set-url origin https://<USERNAME>:<PASSWORD>@github.com/path/to/repo.git

make sure to change USERNAME to your git username and PASSWORD to your new git password.

Next git push should work for you.

Learn more about it in this article

Gideon Babu
  • 336
  • 2
  • 5
  • 11
2

For me, running git on Windows7 using git-bash, running:

git push origin master

Got it working. That prompted Windows7 to ask again for my git creds, and then stored them (whereever Windows does), to update the password.

Eric Manley
  • 1,049
  • 10
  • 8
2

Ok, the original post is quite old, but it's the top result in Google and none of the answers worked for me. Several other SO and GH posts didn't work either. Posting this to help anyone following me here!

My situation is slightly different: Personal GH account, pushing to a private Company repo, using SSH and the git command line on Mac. My password is not stored either in my .gitconfig nor in any keychain nor in git credential.helper.

In the example below PersonalName is my GH account, CompanyName is the company (the owner of the repo on GH) and RepoName is the repository.

My original error message was somewhat different also: attempting git push origin master resulted in

remote: Repository not found.
fatal: repository 'https://github.com/CompanyName/RepoName.git/' not found

The remote was working before my GH password change, and I didn't want to remove the remote because I had local changes that I needed to push.

Eventually a reply by seveas to this question on the GitHub Community Forum pointed me in the right direction. The key thing was to link my GH account name with the remote (private) repo.

This worked for me:

git remote set-url origin https://PersonalName@github.com/CompanyName/RepoName.git

Then

git remote show origin

prompted with

Password for 'https://PersonalName@github.com': 

I was able to enter my new password, see the remote details and git push origin master succeeded.

ChalkBoard
  • 101
  • 1
  • 5
2

If you have setup Github 2FA Auth, you need a personal access token (in place of your github password in git cli), follow this instructions to create it: https://help.github.com/en/github/authenticating-to-github/creating-a-personal-access-token-for-the-command-line

Then do something like

git checkout master

git pull origin <--- At this point you'll be asked for your credentials, enter your normal github user and as password paste the token generated in the link above.

Community
  • 1
  • 1
0

I encountered this issue after changing my GitHub password and attempting to push. It appears the issue was caused by a credential provider which became invalid following the password change. I ran the following commands to ensure I unset the credential provider in question:

  1. git config --system --unset credential.helper (required sudo)
  2. git config --global --unset credential.helper
  3. git config --local --unset credential.helper

Following this, I re-attempted pushing and was successfully able to authenticate my GitHub account.

SeanTwomey
  • 21
  • 2