git多用户配置
场景
在git的使用中,经常会出现这种情况:在公司有一个git账户,github上有个人账户,希望在同一台电脑针对不同的项目使用不同的账号。
此时就需要进行git多用户配置
-
创建用户
- 全局用户
git config --global user.name "globalUser" git config --global user.email "global@email.com"
- 局部用户
cd 到项目所在目录,或在项目目录打开git bashgit config user.name "workUser" git config user.email "work@email.com"
- 全局用户
-
生成ssh-key
针对不同账户保存不同文件名ssh-keygen -t rsa -C "global@email.com" Enter file in whict to save the key (/c/Users/Administrator/.ssh/id_rsa): id_rsa ssh-add ~/.ssh/id_rsa
ssh-keygen -t rsa -C "work@email.com" Enter file in whict to save the key (/c/Users/Administrator/.ssh/id_rsa): work_id_rsa ssh-add ~/.ssh/work_id_rsa
-
将生成的ssh-key添加到github和公司git