Home > front end >  GITHUB ERROR: Permission to user2/repository-name.git denied to user1
GITHUB ERROR: Permission to user2/repository-name.git denied to user1

Time:09-29

Stuck with this issue for the past few hours and cant find a solution. So here we go. Apologies for the long question.

I have two Github accounts on my Macbook

  1. Personal account with username - user1
  2. A company account with username - user2

I was using the personal account mostly and am now trying to push to the company account on this laptop.

While pushing I get the error

ERROR: Permission to user2/repository-name.git denied to user1.
fatal: Could not read from remote repository.


Please make sure you have the correct access rights
and the repository exists.

It is a completely new repository that I am trying to push to, following the instructions that Github provides for new repositories.

I checked

git config user.name
git config user.email

Both are related to user2.

git config credential.helper

returns osxkeychain. I deleted the github related access from there. Now if I run the below command from the terminal, it just hangs and does nothing.

git credential-osxkeychain erase https://github.com

Running this command also returns the correct details

git remote get-url --all origin

Response is

[email protected]:user2/repository-name.git

I also deleted and re-added my ssh keys to the company github account.

I am out of sorts here, not knowing what to try further. Please help!!

CodePudding user response:

So that it may help someone in the future

My issue was that I had the same key still added to my old account. Using that key, it was still trying to use my old account in the new repository. That is why it was saying that the old user did not have access to the new repository.

If you need to use both accounts, here is an article on how to Handle multiple Github accounts on MacOS.

CodePudding user response:

[email protected]

This is an SSH URL, which means the credential.helper is not used at all, considering it caches credentials (username/token) for HTTPS connection.

If you want to make sure to use user2's credentials, you can:

  • Related