remote: Permission to *****newuser.git denied to *****1stusername

Viewed 3238

in Visual studio code

i spent a lot more time for this, I'm trying push my deleted project that is coming from 1st account github into an existing repository in new another account, but I'm getting error like this :

$ git push -u origin main
remote: Permission to username/project_name.git denied to first_account_username.
fatal: unable to access 'https://github.com/user_name/project_name.git/': The requested URL returned error: 403 

i tried those command line for push an existing repository in new account, please let me know what'd i miss ?

git remote add origin https://github.com/user_name/project_name.git
git branch -M main
git push -u origin main
3 Answers

Git obviously tries to push code to your new repository using your old username. Add you new username explicitly to the URL:

git remote set-url origin https://user_name@github.com/user_name/project_name.git

Or use the SSH syntax:

git remote set-url origin user_name@github.com:user_name/project_name.git

Question :

$ git push -u origin main

remote: Permission to username/project_name.git denied to another_username

fatal: unable to access 'https://github.com/user_name/project_name.git/': The requested URL returned error: 403

Answer :

  1. Above the Setting icon in visual studio code there will be a Account Sign in logo icon, click and check it is login with another account or not ?

  2. If it is log in with another Account you will be get the same error continuously... So,

  3. The solution is : You should sign out the other Account in the visual studio and then try in visual studio code terminal following code given below...

$ git push

  1. Then it will ask username and password you should enter the correct details and it will work perfectly.

Check what configuration helper you do have: it might have cached the wrong credentials (from the old users).

git config --global credential helper

Adjust you PATH to use said credential helper.

If you are on Windows, in a CMD, set a simplified PATH like:

set PATH=C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\
set "GH=%ProgramFiles%\Git"
set "PATH=%GH%\bin;%GH%\cmd;%GH%\usr\bin;%GH%\mingw64\bin;%GH%\mingw64\libexec\git-core;%PATH%"

Then type in the same CMD:

 printf "Host=bitbucket.org\nprotocol=https\nusername=old_username" | git credential-manager-core erase

Replace:

  • manager-core by your actual credential helper, as returned by git config --global credential helper
  • old_username by the old username GitHub account

Then try again.

Related