113

I'm trying to upload my repo on github and go through all the steps up to:

git push -u origin master

at that point it gives me the following error:

remote: Permission to samrao2/manager-4.git denied to samrao1.

fatal: unable to access 'https://github.com/samrao2/manager-4.git/': The requested URL returned error: 403

I think the issue is that i was logged into another Git account before "samrao1" and now i am trying to push to "samrao2".

Can someone help me reset this to where i can successfully push to "samrao2". I am assuming i will be prompted for my password the first time I try to do it.

John Smith
  • 7,243
  • 6
  • 49
  • 61
Sam Rao
  • 4,361
  • 5
  • 19
  • 21

22 Answers22

185

Unable to access https means: this has nothing to do with SSH (and switching to SSH, while possible, does not explain the original issue)

This has to do with credential caching, meaning Git will be default provide the credentials (GitHub account and password PAT Personal Access Token) of the old account while you are trying to push to the new account.


Reminder, most Git repository hosting service uses token as password, not your actual user account password.
For instance, GitHub no longer accept password since Aug. 2021.


See if you have a credential helper that would have cached your (old account) credentials (username/password) used to authentication you.

git config credential.helper 

On Mac, as commented by Arpit J, just goto/open your keychain access->search for github.com related file->and edit credentials there.

https://help.github.com/assets/images/help/setup/keychain-access.png

See "Updating credentials from the OSX Keychain"

On Windows (And, in 2021, possibly Linux or even Mac), that would be the Windows Credential Managers GCMC: Git Credential Manager.
Open the Windows Credential Store, and see if the first user is registered there: delete that entry, and you will be able to authenticate with the second user.

(Here is an example for BitBucket)

https://kwilson.io/blog/wp-content/uploads/2015/01/4-store.png


In command-line (see git credential), for a manager core credential helper:

  • Get the old password or token:

    printf "protocol=https\nhost=github.com\nusername=<me>" | \
      git credential-manager-core get
    
    # output:
    protocol=https
    host=github.com
    username=<me>
    password=<old_password_or_token>
    
  • Remove the old password:

    printf "protocol=https\nhost=github.com\nusername=<me>" | \
      git credential-manager-core erase
    

(Replace <me> by your GitHub user account name)

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • 1
    this worked. Thanks. I went into the Mac Keychain and deleted a acouple of records pertaining to Github. It then prompted me for the password and it worked just great! Thanks!! – Sam Rao Nov 24 '17 at 20:34
  • 2
    Thnx!! For ppl on MacOS, just goto/open your keychain access->search for github.com related file->and edit credentials there. Sometimes it takes the default logged in account and stores it there. – Arpit J. Nov 09 '18 at 05:36
  • 2
    @ArpitJ. Thank you. I have included your comment in the answer for more visibility. – VonC Nov 09 '18 at 07:19
  • 1
    Thank you. This almost drives me crazy. I must remember it. – Jeff T. Sep 30 '19 at 10:11
  • 1
    @JeffT. You are welcome. I have edited the answer to include the command-line alternative. – VonC Sep 30 '19 at 14:51
  • Thank you so much, it was almost a headache – Mir Stephen Nov 27 '19 at 03:26
  • In your Keychain Access check existing entry of git hub remove or update them – Giriraj.Mulay Aug 03 '20 at 11:10
  • I tried removing github entry in keychain and tried to re-login using correct username and password/PA token still the issue of permission denied exists for me – philomath Aug 18 '21 at 06:08
  • 1
    @philomath Could you ask a separate question? That will be easier to answer than here, buried in the comments. – VonC Aug 18 '21 at 06:40
  • @Kaff1n8t3d Glad to know this is helpful. I actually use this at work these days all the time! – VonC Aug 06 '22 at 00:05
  • 1
    Thank you for this, This helped me! I was able to upload to my account. I had originally set up Git through Visual Studio for school. One of those, "just click this and that" to get everything set up. So I had created a username just to use for school and now I am using my preferred account to put my projects in. I could not push and it was referencing the school username. I could not find a file in the Git files. After deleting all of the Github credentials saved in my windows "Credential Manager". I was then able to push and had to auth one time and then it was good to go. – Kaff1n8t3d Aug 06 '22 at 00:09
31

Resolved this error by updating my username and credentials:

git config user.name "new name"
git config credential.username "new name"
13

Here 403 (error) means credentials errors or that you don’t have permission to push.

Solution

For Windows

click on window button > credential manager > Windows credentials > Generic credentials

Next, remove or edit the Github keys.

For Mac

1-In Finder, search for the Keychain Access app.

2In Keychain Access, search for github.com.

3-Find the "internet password" entry for github.com.

4-Edit or delete the entry accordingly.

Pavan Tanniru
  • 176
  • 1
  • 2
  • 10
  • 1
    The Mac -> Password solution will still require a Personal Access Token -> Please see https://github.blog/2020-12-15-token-authentication-requirements-for-git-operations/ for more information. – jimmyNames May 22 '22 at 11:29
9

I'm not sure what the issue is, but since you mentioned not knowing what having the "right keys installed" means, I'm going to assume you have not set up your computer to authenticate to your Github repository via SSH.

This guide should show you how to do that: Adding a new SSH key to your Github account

Also, I would suggesting using 'git://github.com/samrao2/manager-4.git/' for your remote URL rather than 'https://github.com/samrao2/manager-4.git/'. The latter requires you to enter a password each time, whereas the former will authenticate via SSH, which is far less irritating. You can change the remote URL in your repository to use the git protocol, instead of https, by typing:

git remote set-url origin git://github.com/samrao2/manager-4.git

from within your project directory.

Clinton
  • 313
  • 1
  • 5
8

If you are using MacOS, you can

  1. go to KeyChain Access,
  2. Search for "GitHub",
  3. then when then result "github.com" pops up, change the account or password to your new account, and save.

Then you are all set!

Novus
  • 791
  • 8
  • 13
8

Appreciating VonC's answer.

To simplify and add into it, one can follow below simple steps:

  1. Remove all GitHub entries from (Windows) Credential Manager
  2. Set useHttpPath = true in Git global configuration

git config --global credential.useHttpPath true

You can validate this by checking

git config --global -e

This will create a different entry for each user account.

8

I was facing the same issue I have resolved using below command

git config --global credential.useHttpPath true

7

I had a similar issue and what found out its two things you need to verify:

  1. The key chain issue that has adequately been discussed above;
  2. Git recently stopped using passwords, you need to instead generate a personal access token. NOTE THIS IS IMPORTANT and the source of the problem I had, on the creation of token ensure permission are granted to the token on Github under developer option.

Permission scope under developer option

Teddy
  • 133
  • 2
  • 5
  • Good point. I have edited [my own answer](https://stackoverflow.com/a/47466980/6309) to reference tokens. – VonC Dec 09 '21 at 10:12
4
  1. Multiple users generate their own ssh key, Generating a new SSH key and adding it to the ssh-agent

  2. Adding a new SSH key to your GitHub account

  3. Alice Repository, git bash:

    • git config user.name "Alice"
    • git config user.email "alice@email.com"
    • eval $(ssh-agent -s),
    • ssh-add ~/.ssh/alice.private
    • ssh -T git@github.com, Testing your SSH connection
    • Git other operations
  4. Bob Repository, git bash:

    • git config user.name "Bob"
    • git config user.email "bob@email.com"
    • eval $(ssh-agent -s),
    • ssh-add ~/.ssh/bob.private
    • ssh -T git@github.com, Testing your SSH connection
    • Git other operations
山茶树和葡萄树
  • 2,050
  • 1
  • 18
  • 18
2

For windows, just remove git account from credential manager.

  • Hello! It looks to me like this duplicates what's already covered in the above answers. Can you explain how this is a new and different answer (or suggest an edit on a different answer if it needs to be clarified!). Thank you!! – Edward Feb 16 '23 at 21:57
1

The problem is you are trying to push into new github account using old github account's ssh key, so generate a new SSH key for the new github account using this link https://help.github.com/en/github/authenticating-to-github/error-permission-to-userrepo-denied-to-userother-repo and then add it your github account. After this try to push, it works

0

I have one personal account and one business account at Github. I commit and push changes to both accounts at the same time.

What I did was 1) to run personal and business projects at separate sessions; 2) to set the URL for one account with an SSH link, and leave the URL as normal (HTTPS) for another account.

pinawa
  • 129
  • 6
0

You can solve this issue by revoking the access of 2nd account "samrao1" from that specific repo that you have previously connected.

bad_coder
  • 11,289
  • 20
  • 44
  • 72
0

just go to Control Panel\User Accounts\Credential Manager\Edit Generic Credential

enter image description here

and update your git Credential

Sourabh Gera
  • 862
  • 7
  • 7
0

if you are still having problems with the same, uninstall git and re-install again. That worked for me . thanks

  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Nov 17 '21 at 05:04
0

Check your personal access token. Edit the scopes in your token. I checked all the access options in the token. Doing this, the error did not come. https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token

0

ONLY IF you've used git cli BEFORE on your machine

Then simply open the credential manager on your system by pressing start button and type "Credential Manager" and switch to the "Windows Credentials" tab.

Delete the existing saved account associated with https://github.com like following:enter image description here

Now try pushing code again, this time an authentication prompt will be popped up, authenticate your github account and congratulations, your code is hosted onto the given branch of desired repository.

Shoaib Khalil
  • 1,874
  • 17
  • 10
0

I faced same problem and then removed the git credential from windows credential manager

0

Important: Remember to set your token permissions correctly.

I had the same problem until I changed the permissions to allow full repo access: enter image description here

joanis
  • 10,635
  • 14
  • 30
  • 40
0

If you're using git credentials helper

open the ~/.git-credentials file and change your token if it is expired,

check also your GitHub username if it's correct!

Hamza AZIZ
  • 2,582
  • 1
  • 9
  • 18
0

For Linux > Go to /home and delete the .git-credentials file. Now you will be asked for your email and password. Please note that instead of password provide your access token.

0

This same situation happened for me also on my Mac.I solved this situation by following these steps.

  1. Sign in to your first git hub account samrao1.

  2. Next goto settings->Developer settings->personal access tokens->tokens (classic) ->generate new token -> generate new token (classic).

  3. Provide token name and generate token.

  4. copy that token and save it in notepad.

  5. In application, search keychain access.

  6. In keychain access, search for GitHub, click on GitHub and change its password portions using the generated tokens and save it.

Repeat these 6 steps for second GitHub account on private window mode on safari. it will work. While pushing, asks for username and password.Provide your username first and on password area paste these generated token related to respective accounts.

Note: while creating personal access token some access permission have to be check listed.