Git multiple users
1. Different user email/name for different remote
Matching the specific domain
sh
vim ~/.gitconfig
ini
[user]
name = yunyuyuan
email = [email protected]
[includeIf "hasconfig:remote.*.url:[email protected]:*/**"]
path = .gitconfig-another
Add a configuration
sh
vim ~/.gitconfig-another
ini
[user]
name = another-user
email = [email protected]
2. Different identity for specific user
Generate a new identity
sh
ssh-keygen -f ~/.ssh/id_rsa_another
Config the magic Host
sh
vim ~/.ssh/config
ini
# default user
Host github.com
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa
Host github.com-another
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa_another
Then use this to git clone
:
sh
git clone [email protected]:default_user/xxx.git
git clone [email protected]:another_user/xxx.git
3. Custom SSH port
sh
vim ~/.ssh/config
ini
Host git.example.com
HostName git.example.com
User git
Port 222