Hello Friends,
As I have two different GitHub accounts one is office account and another is the personal account.
So every time when I want to do some git commands that time I have to delete existing account from the keychain.
Then add a new account, which is really frustrating so I did some research and finally able to add multiple accounts in the keychain.
The reason behind it as when we use GitHub commands then our credentials are stored in cache and keychain so we don’t require to type every time.
following are the commands which we needs to be followed:
To check your current credentials cached in keychain you can use the following command:
$ git credential-osxkeychain get
then press the enter button twice.
Now come to the point :
In the terminal enter the command:
$ git config –global –edit
This will add open git config file in the terminal to edit If you haven’t already and If you want to open with other editors then you can use the following command ( I am using the sublime editor).
$ git config –global core.editor “subl -n -w”
If you are not able to edit from terminal then you can find out the config file from Finder and your config file is stored at $HOME/.gitconfig on all platforms.
Or you can use the directly following command to edit with nano :
$ nano ~/.gitconfig
(this will exists if you already have any global configuration.)
Now you have config file opened you can check useHttpPath is defined or not if it’s defined then set its value to true, otherwise, you can add following code at the end of the file.
[credential]
helper = osxkeychain
useHttpPath = true
This command will instruct git that any credentials use to login should only be associated with the full repository path, not for the full domain.
Now you can enjoy with multiple git accounts.
Cheers !!!