Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
657 views
in Technique[技术] by (71.8m points)

git - GitHub: 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...

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The conditional include that I detail here is only for commit authorship (user.name/email).

This has nothing to do with authentication (credentials: username/password)

Those are probably cached in a credential manager (like the linux osx-keychain)
Check the output of:

git config credential.helper

If you can, use instead SSH keys per environment, as I illustrate there: then you can easily maintain different identities for the same remote repo (github.com)


Note: the GCM (Git Credential Manager) installed alongside Git for Windows does not, as stated in issue 363, support multiple users per Uri.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...