Reputation: 4551
I'm trying to upload to my repo on GitHub. I 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 assume I will be prompted for my password the first time I try to do it.
Upvotes: 127
Views: 437460
Reputation: 362
If you are running Windows, skip to step 2.
brew install --cask git-credential-manager
brew upgrade --cask git-credential-manager
git config user.name "username"
git config credential.username "username"
git push
then login to Github through the pop-up.Read more: https://github.com/git-ecosystem/git-credential-manager/blob/main/README.md
Upvotes: 2
Reputation: 6345
My repo was built with the Visual Studio IDE, but I was using the Windows command line for git commands. My exact git push
error on the command line was
remote: Permission to <username1>/<repo name>.git denied to <username2>.
fatal: unable to access 'https://github.com/<username1>/<repo name>.git/': The requested URL returned error: 403
I tried removing credentials from the Windows Credential Manager without success.
Result: Successfully pushed to origin/main.
Upvotes: 0
Reputation: 11
This same situation happened for me also on my Mac.I solved this situation by following these steps.
Sign in to your first git hub account samrao1.
Next goto settings->Developer settings->personal access tokens->tokens (classic) ->generate new token -> generate new token (classic).
Provide token name and generate token.
copy that token and save it in notepad.
In application, search keychain access.
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.
Upvotes: 1
Reputation: 51
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.
Upvotes: 0
Reputation: 41
For windows, just remove git account from credential manager.
Upvotes: 4
Reputation: 2937
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!
Upvotes: 0
Reputation: 11
Important: Remember to set your token permissions correctly.
I had the same problem until I changed the permissions to allow full repo access:
Upvotes: 1
Reputation: 117
I was facing the same issue I have resolved using below command
git config --global credential.useHttpPath true
Upvotes: 10
Reputation: 711
Resolved this error by updating my username and credentials:
git config user.name "new name"
git config credential.username "new name"
Upvotes: 59
Reputation: 344
Appreciating VonC's answer.
To simplify and add into it, one can follow below simple steps:
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.
Upvotes: 11
Reputation: 11
I faced same problem and then removed the git credential from windows credential manager
Upvotes: 0
Reputation: 2402
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:
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.
Upvotes: 0
Reputation: 1323115
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.
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)
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)
Upvotes: 197
Reputation: 153
I had a similar issue and what found out its two things you need to verify:
Upvotes: 8
Reputation: 46
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
Upvotes: 0
Reputation: 1
if you are still having problems with the same, uninstall git and re-install again. That worked for me . thanks
Upvotes: 0
Reputation: 1006
just go to Control Panel\User Accounts\Credential Manager\Edit Generic Credential
and update your git Credential
Upvotes: 0
Reputation: 1
You can solve this issue by revoking the access of 2nd account "samrao1" from that specific repo that you have previously connected.
Upvotes: 0
Reputation: 311
Here 403 (error) means credentials errors or that you don’t have permission to push.
click on window button > credential manager > Windows credentials > Generic credentials
Next, remove or edit the Github keys.
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.
Upvotes: 15
Reputation: 151
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.
Upvotes: 0
Reputation: 51
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
Upvotes: 1
Reputation: 2368
Multiple users generate their own ssh key, Generating a new SSH key and adding it to the ssh-agent
Alice Repository, git bash:
git config user.name "Alice"
git config user.email "[email protected]"
eval $(ssh-agent -s)
, ssh-add ~/.ssh/alice.private
ssh -T [email protected]
, Testing your SSH connectionBob Repository, git bash:
git config user.name "Bob"
git config user.email "[email protected]"
eval $(ssh-agent -s)
, ssh-add ~/.ssh/bob.private
ssh -T [email protected]
, Testing your SSH connectionUpvotes: 8
Reputation: 861
If you are using MacOS, you can
Then you are all set!
Upvotes: 9
Reputation: 323
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.
Upvotes: 10