7

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
1
  • This problem is not related to VS code, gitlab or pull requests. Please remove the according tags and the information about it in the question. Instead, add the git tag. Commented Dec 4, 2021 at 11:15

6 Answers 6

11

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://[email protected]/user_name/project_name.git

Or use the SSH syntax:

git remote set-url origin [email protected]:user_name/project_name.git
2

First check your credentials:

git config --global user.name
git config --global user.email

Then change with:

git config --global user.name "email"
git config --global user.email "[email protected]"

If you set another credential before, will have problem use git config credential.username "username"

1

Just see the same problem and here is my solution: Before we generate the token. We need to enable some elements of "select scopes in github settings as show below. enter image description here

I just select several elements and generate key. Therefore I can push the code after fill username and password(generated key).

0

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.
0

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.

2
  • It's confidential dude.... Please dit your wrong anweser. Commented Jun 10 at 11:14
  • @NicholasJela Yes, the goal is to check that confidential information locally, from your own local credential manager. What kind of edit do you want me to do?
    – VonC
    Commented Jun 10 at 20:26
0

The solution that worked for me was to remove github credentials stored in my windows credential manager. I did this by following steps here https://github.com/atom/github/issues/2395

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.