Git 多用户配置
MacOS 系统
故事背景
日常工作中我习惯带自己的电脑去公司上班,公司使用 Gitlab 管理代码,但是个人使用全球同性交友平台 Github 管理代码。在公司时你需要将公司代码提交到 Gitlab 中,下班后个人代码提交到 Github ,这两个仓库不仅地址不一样仓库的用户名和邮箱📮都不一样,这里就需要我们在 git 中配置多个 git 用户以此来满足不同的代码提交需求。
多用户配置
用户名 | 邮箱 | 代码管理 |
---|---|---|
tom | [email protected] | Github |
jerry | [email protected] | Gitlab |
为用户生成钥匙🔑对
-
生成 github 仓库钥匙对
ssh-keygen -t rsa -C “[email protected]”
回车后有如下提示
Generatingpublic/privatersa key pair.Enter fileinwhich to save the key (/Users/test/.ssh/id_rsa):
再提示末尾输入公钥名字(默认为 id_rsa),为了和 gitlab 区分,我们这里使用 id_rsa_github