Tuesday, October 29, 2019

Manage multiple git accounts for github authentication on Windows 10 / Mac

By default, Windows 10 manages git authentication username and password automatically without you to configure the username and password from git configuration. The credential is saved in Windows credential store, and can be accessed from Control Panel->User Account->Manage Your Credentials->Windows Credentials.

As a result, when checking the username and password information from git configuration by running
git config --list
or
git config --global --list
You will not see the git username and password information there.

One problem is, Windows only allows to store a single username and password for your github credential, if you have more than one github accounts, then in order to switch to different git account, you will have to update the username and password from Windows Control panel's Manage your credentials page. (open from: Control Panel -> Credential Manager ->Windows Credentials)

On Mac, the git account information is saved in keychain tool. To switch between different git user account, first open KeyChain tool, In Category section, select all items. Then input "github" in top right search text field, and select the matched item for githbu, and update the user name and password for the record.

Actually, there is simple way to store and use multiple git accounts on a single windows box by following the below steps:
1. run
git config --global credential.github.com.useHttpPath true
from command line
2. open Windows control panel->Credential Manager->Windows Credentials and delete the saved github.com credential if existing.


Note, Github is about to deprecate password authentication, and will replace the password with personal token. If you use gitbut's username/password to log, then you will need to replace the password with personal token in your saved github credential in windows or mac.
To do so, first go to github's "Settings->Developer settings->Personal access tokens" web page to generate a new personal access token, and then copy the generated token, and replace the saved  password with the personal token. The username/personal token can be used for authentication in the same way as username/password. 

No comments:

Post a Comment