简体   繁体   中英

How to switch github account using git without deleting credentials in manage windows credentials manager?

I have been referring this , whenever I want to add one of my project from one account repo(source) to another account repo(destination).

So I first do this . And when I try to push into the destination repo ( I have created another folder out of source folder for destination, where I have pulled stuff from destination repo before pushing ) it will give me the following error(as we can see in the video here ):

remote: Permission to destination_userName/destination_Repo.git denied to source_Repo.
fatal: unable to access 'https://github.com/dest_userName/dest_Repo.git/': The requested URL returned error: 403

After pull, configuring user.name, user.email, it still gives that error.

So I have been following solution from video but it is tiresome to delete credentials everytime and add again for both accounts. I also tried creating SSH Key and adding into destination github account. But that also not worked for me.

Is there any other solution to work it out?

If Windows credential manager is working, credential.helper has been set to manager . To use another account, you could either add the account to the repository URL or specify credential.username . foo is the new account.

git push https://foo@github.com/dest_userName/dest_Repo.git bar

or

git -c credential.username=foo push origin bar

The first one is a bit troublesome if you need to type or paste the long URL every time. You could add a new remote for it,

git remote add baz https://foo@github.com/dest_userName/dest_Repo.git
git push baz bar

You mentioned you had created and added SSH key but it couldn't work. It could be because you still used the HTTPS URL ( origin , aka https://github.com/dest_userName/dest_Repo.git/ ). Instead, the SSH URL is expected, which is git@github.com:dest_userName/dest_Repo.git .

git push git@github.com:dest_userName/dest_Repo.git bar

or

git remote add baz git@github.com:dest_userName/dest_Repo.git
git push baz bar

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