3

I am in VS code as a particular git user (say user1) and want to pull & commit changes from one of my other github accounts (user2). After pulling my repository & commiting when I push I get the error of type:

remote: Permission to user2/repository.git denied to user1.
fatal: unable to access 'https://github.com/user2/repository.git/': The requested URL returned error: 403

So I assume this error is simply because I am 'logged in' as user1 in VS code. But how exactly can I change myself to user2 to be able to work on this repository?

I am using Macbook. I have tried many variety of ways e.g. changing to SSH cloning & resetting git config without any luck. There has to be a very simple solution to this problem which should be very basic. I was expecting it will ask me for credentials for the second account but it never did.

Satyajit Das
  • 2,740
  • 5
  • 16
  • 30
  • Have you searched the internet for an answer? A quick Google search lead to this, which would possibly work: https://stackoverflow.com/questions/28238037/git-log-out-user-from-command-line?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa – Matt Runion Sep 23 '18 at 14:17
  • 1
    This did not work for me. – Satyajit Das Sep 23 '18 at 14:19
  • Then the only option that comes to mind is to use the command line and change users.authenticate, then commit your code. – Matt Runion Sep 23 '18 at 14:22
  • Can you elaborate bit more? I couldn't find any tag named users.authenticate. – Satyajit Das Sep 23 '18 at 14:31
  • That was a typo on my part, sorry about that. I was saying to use the command line to change users/authenticate -- meaning to use the command line to change your user, or to re-authenticate as another user. – Matt Runion Sep 23 '18 at 14:34

3 Answers3

0

Deleting github information in Keychain worked as explained here.

Although it doesn't let one use multiple accounts at a time.

Satyajit Das
  • 2,740
  • 5
  • 16
  • 30
0

On ubuntu 19 I ran into the same problem as the title describes.

To fix it I had to first sign out of my GitHub account in the web browser, NOT the web browser you normally use, but the browser that the github extension in vscode opens after you click the Allow option to "The extension 'Github' wants to sign in using Github.".

Instructions:

  1. Sign out of your (wrong) user account by clicking the Accounts icon at the bottom left of the screen and then "Sign out". If it is not there, right click and deselect "Hide Accounts".

The accounts icon

  1. Push, pull or clone your repo. vscode asks: "The extension 'Github' wants to sign in using Github: Allow, Cancel". Click allow. A firefox window opens, but note that this window belongs to vscode.

A firefox window beloning to vscode opens

  1. Press CTRL+T to open a new tab. Go to https://github.com. Sign out (top right of the web page).

  2. Close the firefox window.

  3. Repeat step 2, but this time click "Continue". Login to github with correct account.

Try pushing, cloning or pulling again.

bwack
  • 1
  • 1
0

I ran into a similar situation I was using Azure git so my solution was as follows:

  1. Remove stored credentials by running the following command:
    git config --global --unset credential.helper
  2. Do your pull/push request