Unable to change Git account

2020-01-23 09:52发布

问题:

I tried to push to my repository, but I got the error below:

git push origin master
remote: Permission to PhanVanLinh/phanvanlinh.github.io.git denied to edgarphan.
fatal: unable to access 'https://github.com/PhanVanLinh/phanvanlinh.github.io.git/': The requested URL returned error: 403

Before, I was using username edgarphan, but I have already changed it to PhanVanLinh, but it still keeps edgarphan.

I have tried to delete the project and clone again, uninstall Git and reinstall, but it won't work.

Global configuration file

How can I fix this issue?

回答1:

This has nothing to do with your user.name/user.email settings: those are for authorship in a commit. They are not used for authentication when you push to a repo.

If Git does not ask you for your GitHub (new) username/password, that means Git for Windows is using a Git credential helper called "manager" (do a git config credential.helper to confirm it)

Meaning: it is caching your old credentials and is reusing them automatically.

In that case, go to the Windows start menu (), type "credential" and select the Windows tool "Windows Credential Manager".

In it, you will find an entry git.https://github.com, which you can edit, and where you can enter your new GitHub username/password.

Then try and push again.



回答2:

Try to find out the Git configuration file. For a Windows machine it probably located at

C:\Users\<user_name>\.gitconfig

This command may open up the configuration file too. Then you can just edit and save:

git config --global -e

And after setting the configuration, do:

cd /path/to/new/local/repo
git remote add origin https://github.com/PhanVanLinh/phanvanlinh.github.io.git
git push -u origin master