26

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.

Enter image description here

Global configuration file

Enter image description here

How can I fix this issue?

Community
  • 1
  • 1
Linh
  • 57,942
  • 23
  • 262
  • 279

3 Answers3

71

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 (Windows start), type "credential" and select the Windows tool "Windows Credential Manager".
enter image description here
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. Enter new credentials

Then try and push again.


With more recent Git version (2.32+, Q2 2021), assuming <C:\path\to\git>\usr\bin and <C:\path\to\git>\mingw64\libexec\git-core are in your %PATH%, you can do the same removal in command-line:

printf "protocol=https\nhost=github.com\nusername=xxx"| git-credential-manager-core erase
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • @SeakyLone Than please ask a separate question with more details on your current setup. For instance, if your remote URL is an SSH one instead of an HTTPS one, you would not see anything in the credential manager indeed (since it deals with credentials for HTTPS queries only) – VonC May 24 '20 at 11:13
1

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
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
LogicalAnt
  • 907
  • 3
  • 12
  • 28
1

I had the same issue where I had not set up the username and password for git and the following solved my issue.

Note: If you have Enable Two factor authentication for GitHub disable it for a while

  • Step 01
Goto Control Panel -> User Accounts -> Credential Manager -> Windows Credentials
  • Step 02
Goto Generic Credentials section -> Add a generic credential
  • Step 03 - Fill the fields
Internet or network address : git.https://github.com
User name                   : your github username
Password                    : your github username

And now click on Ok. This will solve the problem of failing to push the repository

Niroshan Ratnayake
  • 3,433
  • 3
  • 20
  • 18