macOS配置GitHub和GitLab共存

  1. 查看之前是否设置过全局的user.nameuser.email:

git config --global --list

  1. 如果已设置,则删除

git config --global --unset user.name "你的名字"
git config --global --unset user.email "你的邮箱"

  1. 生成SSH Key:

ssh-keygen -t rsa -f ~/.ssh/id_rsa.github -C "abc@qq.com"
ssh-keygen -t rsa -f ~/.ssh/id_rsa.gitlab -C "abcdef@qq.com"

  1. 获取公钥粘贴到对应平台:

cat id_rsa.github.pub
cat id_rsa.gitlab.pub

  1. 配置config:

cd ~/.ssh && touch config
vim config

# github
Host github.com
HostName github.com
User GaiheiluKamei
IdentityFile ~/.ssh/id_rsa.github

# gitlab
Host gitlab.google.com  ## 公司提供的网址
HostName gitlab.google.com ## 同上
User git
IdentityFile ~/.ssh/id_rsa.gitlab
Port 2223  ## 公司提供的端口
  1. 验证是否正确:

ssh -T git@github.com
ssh -T gitlab.google.com

git commit 提示:

*** Please tell me who you are.
Run

git config --global user.email "you@example.com"
git config --global user.name "Your Name"

to set your account's default identity.
Omit --global to set the identity only in this repository.

执行:
git config user.email "abc@qq.com“
git config user.name "abc“

原文地址:https://www.cnblogs.com/GaiHeiluKamei/p/13802458.html