15

Everything was working fine, until I create a new GitHub account. When I try to push the code for first time to github server with new account, following error is occurring:

remote: Permission to NEW_USER/NEW_REPO.git denied to OLD_USER.
fatal: unable to access 'https://github.com/NEW_USER/NEW_REPO/': The requested URL returned error: 403

Tried to reset remote url using:

$git remote set-url origin https://username@github.com/user/repo.git ... but not working.

Got one solution here, but for Mac OS. Any ideas how to resolve this. Using git bash version 2.16.1.windows.4.

Thanks

Nicolás Alarcón Rapela
  • 2,714
  • 1
  • 18
  • 29
Mahesh Kakade
  • 283
  • 1
  • 3
  • 11

2 Answers2

34

This happens when two git accounts are being used on same machine. On Windows 7 you need to remove git Credentials from Windows vault.

  • go to Control Panel -> User Accounts -> Manage your credentials.
  • Under Generic Credentials delete entries for github credentials.
  • Try to push code and this time it will prompt you for correct username and password again.

enter image description here

codeworks elegant
  • 1,051
  • 7
  • 11
  • 2
    To complete this aswer for mac users. go to Keychain > Search git > Right Click on github/gitlab/etc creditional > Delete > then username and password will be asked again and problem will be solved – Mehrdad Jul 16 '20 at 20:51
6

You may check for the Git Credentials you are using, and change that with your new account.

As the top answer from the question you mentioned says, using a SSH way by

$ git remote set-url origin git@github.com:new_user/new_repo.git

(and set the SSH Key) instead of HTTPS way is also a workaround.

Geno Chen
  • 4,916
  • 6
  • 21
  • 39
  • Credentials are correct. Somehow it's still referring to old git account user name. Between how to set SSH key ? – Mahesh Kakade Jul 09 '18 at 13:31
  • Or any repo-based credential exists? Set the SSH Key contains the step of "Generating a SSH Key" and "Register a SSH Key to a GitHub account". – Geno Chen Jul 09 '18 at 13:37