简体   繁体   中英

How to change GitHub accounts when trying to push from Git?

So I may have set up Git under an account that I will not be using in the future, and I want to change that account to my personal GitHub account. I would like to push under my personal rather than that one.

If this has any relevance, I've created a separate SSH key for my computer, but as inexperienced as I am, I'm not sure what to do with it.

My ultimate goal is to change the GitHub account I'm under, because whenever I try to push code to my personal account's repository, I get this error message:

$ git push origin master
remote: Permission to maiusername/SURVIVAL2.git denied to SupernovaRobotics.
fatal: unable to access 'https://github.com/maiusername/SURVIVAL2.git/': The requested URL returned error: 403

SupernovaRobotics is what I'm trying to get rid of, but I'm not sure how!

Please help!!

Add your public ssh key to your GitHub account (drop down on the top right, settings, SSH and GPG keys, new SSH key).
Then execute:

git remote set-url origin https://github.com/username/desiredrepo.git

This command changes the repository of origin.1

First, if you are pushing to an https url, changing anything regarding SSH won't matter one bit.

Regarding HTTPS, if the wrong user is consistently used, that means the wrong credentials (username/password) is used by Git. That is because you must be using a credential helper which caches said credentials.

Check what credential helper you are using with:

git config -l | grep credential

The alternative (if you do have changed your ~/.ssh/id_rsa(.pub) keys) is to use an ssh url

git remote set-url origin git@github.com:maiusername/SURVIVAL2.git

Then your new ssh key would be taken into account.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM