github 公司和个人帐号分离
terminal 端需要在 ssh 下配置两个不同的主机。
web gui 又没有好的切换帐号的软件。
https://ayase.moe/2021/03/09/customized-git-config/
浏览器 github 账号的话就用 firefox,firefox 的 container 是真的非常好用,firefox 的几个优势功能之一
git 的的话不想纠结配置只想点鼠标的话,可以使用 fork 这个 git 的 gui,能轻松在几个账号间切换
Host github-guest github.com
HostName github.com
User git
PreferredAuthentications publickey
IdentityFile ~/.ssh/github-guest
IdentitiesOnly yes
暂时是不同公司不同文件夹, 反正顶层 Include ~/.ssh/company1/config 一堆子文件夹下的 config+.pub 还是挺好用的, 相对路径还是香
但是,我还是建议自己私人项目不要使用公司财产(如果电脑是公司发的),上班时间使用公司财产的代码产出所属权归公司。
如果已经有两个 github 账户对应个人和公司的项目,那就其中一个账户的 github 地址用别名好了。
比如~/.ssh/config 配置为:
“`
Host github.com
HostName github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa_github1
User gituser1
Host github2.com
HostName github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa_github2
User gituser2
“`
使用的唯一差别就是下载代码的时候记得把公司项目的 ssh 地址 github.com 改成 github2.com (或者其他别名)
另外使用 includeIf 区分不同目录使用不同.gitconfig,需要本地 git 版本是 2.13.0 以上才支持
在~/目录下面存在三个配置文件,
.gitconfig // 全局通用配置文件
.gitconfig-my // 个人工程配置文件
.gitconfig-work // 公司工程配置文件
全局~/.gitconfig 配置如下
“`
[user]
name = yourname
email = [email protected]
[includeIf “gitdir:~/myspace/”]
path = .gitconfig-my
[includeIf “gitdir:~/workspace/”]
path = .gitconfig-work
“`
个人.gitconfig-my 配置如下
“`
[user]
name = gituser1
email = [email protected]
“`
公司.gitconfig-work 配置如下
“`
[user]
name = gituser2
email = [email protected]
“`