1

I want to change the git account used in my VSCode. I made a new account and don't want to use the old one anymore

What I have tried so far:-

  1. Did everything in this StackOverflow question Change Git Account in VSCode
  2. And in this one Chang git account on VScode
  3. I also have unchecked the GitHub Authentication in VSCode settings!
  4. Read the VSCode documentation about GitHub Integration but they don't mention such things

But I can't seem to get it to work

This is the error I get when pushing my commits

git push -u origin master
remote: Permission to username1/todo-app.git denied to username2.
fatal: unable to access 'https://github.com/username1/todo-app.git/': The requested URL returned error: 403

What can I do to solve this problem?

Thanks in advance

Hussein Al-Mosawi
  • 1,464
  • 3
  • 17
  • 37

1 Answers1

0

First, don't use wincred as suggested in your first link: use manager-core (the Git Credential Manager packaged with a Git For Windows).

git config --global credential.helper manager-core

Second, make sure your Git for Windows is up-to-date (2.35.1.windows.2 in Q2 2022)

Third, clean the old URL from the credential manager

printf "protocol=https\nhost=github.com" | git credential-manager-core erase

Note: git-credential-manager-core.exe is in C:\Program Files\Git\ mingw64\libexec\git-core folder: make sure this is part of your %PATH%.
Same for printf.exe: in C:\Program Files\Git\usr\bin.

Finally, try and push: that should trigger a popup asking for your GitHub credentials: enter the new ones.

Remember: the password must be a PAT (Personal Access Token), which is mandatory since Aug. 2021.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • 1
    The first command worked but when executing the second it gives this:- ```fatal: InvalidOperationException encountered. Invalid input, please see 'https://www.kernel.org/pub/software/scm/git/docs/git-credential.html'``` Can you tell me where the problem is? Thanks – Hussein Al-Mosawi Jun 06 '20 at 19:29
  • @HusseinAl-Mosawi I would first validate the new account using Git in command line, with VSCode closed: try the same `git push -u origin master` from a command line. It should trigger the popup, and you would then enter the new credentials. Once that is working, open VSCode again, and go on working/committing and pushing from there. – VonC Jun 06 '20 at 21:34
  • 1
    I'm sorry but this doesn't work! Because this is literally what I have been doing for the last 2-3 days. – Hussein Al-Mosawi Jun 08 '20 at 13:53
  • 1
    @HusseinAl-Mosawi What version of Git are you using on which OS? – VonC Jun 08 '20 at 14:07
  • 1
    The latest version which is 2.27.0 and Windows 10 Version 10.0.18363 Build 18363 – Hussein Al-Mosawi Jun 11 '20 at 07:13
  • `git: 'credential-manager' is not a git command. See 'git --help'.` – johannes Apr 09 '22 at 09:46
  • @johannes Good point. I have fixed the answer. – VonC Apr 09 '22 at 19:30