Mac上git多账号配置

默认情况

已经配置好一个全局的账号

在此基础上搭建github的个人账号

步骤

新建一个ssh key,保存在id_rsa_jacobma

$ ssh-keygen -t rsa -C [email protected]

$ Enter file in which to save the key (/Users/mayao02/.ssh/id_rsa): /Users/mayao02/.ssh/id_rsa_jacobma

$ Enter passphrase (empty for no passphrase):

$ Enter same passphrase again:

成功后,显示key值并复制到github

$ cat ~/.ssh/id_rsa_jacobma.pub

测试是否能连接到远程仓库

$ ssh -T [email protected]

若未成功,则把该key加到ssh agent

$ ssh-add ~/.ssh/id_rsa_jacobma

配置config

$ vi .ssh/config

添加以下内容

Host jacobma
HostName github.com
IdentityFile ~/.ssh/id_rsa_jacobma

拉下github的项目后,需要配置此项目的账号,否则会以全局的账号名来提交

$ git config user.name "JacobMa1996"

$ git config user.email "[email protected]"

END

你可能感兴趣的:(Mac上git多账号配置)