Mac 配置 Git 多用户

Mac 配置 Git 多用户

之前重装 macOS 把一些配置都删除了,现在开发中需要区分个人和公司的环境,这里重新记录下

Git 多用户

有多种方案,如果只是临时对某个项目配置,直接通过 git config 在工作目录设置就好了

我这里通过指定公司项目路径来设置公司 git 用户信息

新增 .gitconfig-work 文件

1
2
3
[user]
        name = xxx
        email = [email protected]

编辑 .gitconfig

1
2
3
4
...
[includeIf "gitdir:/Users/xx/xx/"]
  path = ~/.gitconfig-work
...

去工作目录检查下是否生效

1
2
3
git config user.name

git config user.email

SSH 多用户

Git 的多用户搞定了,同样我希望 ssh key 也区分公司和其他

重新生成 ssh-keygen -t ed25519 -C "<comment>" -f xxxwork

编辑 .ssh/config

1
2
3
4
5
6
7
8
...
Host xx-git
    HostName git.xx.cn
    IdentityFIle ~/.ssh/xx
    PreferredAuthentications publickey
    IdentityAgent none
    IdentitiesOnly yes
...

配置完成后 ssh -T git@xx-git 验证下

Buy me a coffee
加乘+x 微信微信
0%