go install github.com/YukiAbyss/git-switch@latest
export PATH=$GOPATH/bin:$PATH
ssh-keygen -t -C "your_email@example.com"
# new git a user
git-switch -n
# delete git a user
git-switch -d
# switch git a user
git-switch
# print shell cmd execution information
git-switch -o
$ ls -al $GOPATH/bin | grep git-switch
-rwxr-xr-x 1 yy staff 4402130 1 5 12:10 git-switch
$ ls -al ~/.gitswitchv1.json
-rw-r--r-- 1 yy staff 232 1 16 12:34 /Users/Yuki/.gitswitchv1.json
$ git-switch
Use the arrow keys to navigate: ↓ ↑ → ←
? Select a switch git user:
▸ yuki your_email@example.com /Users/Yuki/.ssh/yuki_id_rsa
tom your_email@example.com /Users/Yuki/.ssh/id_rsa
$ cat ~/.gitswitch.json
[
{
"name": "yuki",
"email": "yy__yyyy@126.com",
"ssh_key_file_path": "/Users/Yuki/.ssh/yuki_id_rsa"
},
{
"name": "nodereal",
"email": "yuki.w@nodereal.io",
"ssh_key_file_path": "/Users/Yuki/.ssh/nodereal_id_rsa"
}
]
When git-switch selects users, the following 2 steps will be performed
- Delete ssh key
- Add/Overwrite git global config
# clear ssh key and add ssh key
ssh-add -D
ssh-add ~/.ssh/id_rsa
# set git config
git config --global user.name {your name}
git config --global user.email {your email}