Monday, May 6, 2019

Multiple git accounts

Using multiple ssh keys for multiple gits:
https://gist.github.com/jexchan/2351996
Add the ssh keys on github

Some possible "git config --list" options are "--local" and "--global"
If you don't specify --global, it takes the local config by default.

To display the actual  “git config” do:
git config --list
git config user.name
git config user.email

Before you commit, you need to be sure you are using the correct one.
You can set it by doing:
git config user.name "abc"
git config user.email "abc@abc.com"

The local config will be saved in .git/config
The global config is saved in ~/.gitconfig

"url" must be a git@something  in .git/config, should not be https. If it is https, use:
“git remote set-url origin git@github.com:me/gg-linux.git”
It will change your .git/config

_______ git clone
Even if the keys are on github, you may want to use a specific name/email
You can use
git clone XX -c user.name=toto -c user.email=toto@toto.com (this will set .git/config)
or
git config --global user.name "xxx"
git config --global user.mail "xxx"
git clone git@github.com:youruser/myj-gh     (need ssh keys)

______________ Just using ~/.ssh$ more config 

Host *.internal 10.*
identityfile ~/.ssh/id_rsa

Host *github.com
identityfile ~/.ssh/id_rsa_github