Separate credentials for two accounts on Windows

I recently created a second GitHub account two separate my work and my private projects (before, I only had the work account). I use https in combination with the Windows credential storage. To automatically select the correct account, I store my private account info in ~/.gitconfig and the work account info in ~/work/.gitconfig as suggested here.

Unfortunately, when I try to push changes in my private repositories, I get the following error:

$ git push
remote: Permission to privateuser/privaterepo.git denied to workuser.
fatal: unable to access 'https://privateuser@github.com/privateuser/privaterepo.git/': The requested URL returned error: 403

I set the remote URL to git remote set-url origin https://privateuser@github.com/privateuser/privaterepo.git like suggested here. Pushing in my work repos still works fine. And when I type git config user.name in my private/work repos, I get my private/work username, respectively - as it should be.

What’s the problem with the new private repositories? Why does git still think I’m workuser, when I try to push to my private repos? Does it have to do something with the Windows Credential storage, which I used to store my work credentials? It never asked for the password of my private account…

I tried to get help on stackoverflow, but it seems nobody can answer the question :frowning:

You could look at the credentials management from Windows. You can find that by going to the Control Panel, then searching for “credentials”.

I believe that if Git can’t find any credentials stored there it will just ask you for user/password every time.

2 Likes

Yes, deleting my github credentials from the Windows credential manager let to github asking me again for my account info, when it did the next push. But it it then uses these credentials for all further github interactions, i.e., not allowing two access to two different github accounts.

I tried manually adding generic credentials git:https://privateuser@github.com and git:https://workuser@github.com, but they were simply ignored and didn’t change anything. Even though, I set git remote set-url origin https://privateuser@github.com/privateuser/privaterepo.git and git remote set-url origin https://workuser@github.com/workuser/workrepo.git

1 Like

I guess it happens because Windows credential manager stores a password by domain and the domain for both git:https://privateuser@github.com and git:https://workuser@github.com is the same. It seems that the only solution is to remove windows credentials manager

git config --system--unset credential.helper

and either make git prompt for credentials each time or use store helper to remember project specific credentials:

git config credential.helper store
git config credential.${remote}.username yourusername
git config credential.${remote}.password youruserpassword

you can read more about store here

2 Likes

“It seems that the only solution is to remove windows credentials manager”

git config --system--unset credential.helper

I followed the above advice and after so many different attempts to configure git store to recognize two github accounts, which I understand can be done, found this article on getting windows credential manager to recognize two seperate accounts from the same url. 

git config --global credential.github.com.useHttpPath true

https://dev.to/configcat/lazy-man-s-guide-multiple-github-https-accounts-on-windows-2mad

Haven’t tried it yet, but as soon as I reset git to use windows credential manager again I will. 

Any ideas on how to reverse, git config --system–unset credential.helper? Other than uninstalling reinstalling git for windows. 

2 Likes

What you need to do is to create a new ssh key for your second Github account because by default git is using the key from your first Github account and when you try to push from the second account you will get remote: Permission to privateuser/privaterepo.git denied to workuser. workeruser in this case is your first Github account’s username. So you cant push to your second Github account using the first Github account’s username. Follow this link for help.

Can you tell me ? How Can remove credential.helper manager from git?