Git
Ref: Git 多用户配置
Unset global configuration:
git config --global --unset user.name
git config --global --unset user.email
Check:
git config --global --list
1. Use ssh key for git authentication
Generate key file:
ssh-keygen -t rsa -C "colin@gmail.com" # -C: comment to identify the key
Add public key to GitHub ,GitLab, or etc.
Add private key to localhost:
ssh-add ~/.ssh/id_rsa_github
Let's check:
ssh-add -l
2. Multiple git user:
Edit ~/.ssh/config
:
Host github
HostName github.com
User jitwxs
IdentityFile ~/.ssh/id_rsa_github
Host gitlab
HostName gitlab.mygitlab.com
User lemon
IdentityFile ~/.ssh/id_rsa_gitlab
Test:
ssh -T git@github.com
ssh -T git@gitlab.mygitlab.com
3. Set commit user name for repo
git config --local user.name "name"
git config --local user.email "colin@gmail.com"
Check:
git config --local --list
Last update:
February 23, 2021
Authors: