多git有两种状态
- 多个git账号(user, email)
- 多个认证(identities)
设置多个git账号
条件: git版本号高于2.13(git --version
)
编辑~/.gitconfig
. 注意: 路径后面要加斜杠/
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
# specify multiple users with git
# refs: https://stackoverflow.com/a/43654115 and https://stackoverflow.com/a/48088291
# use `git config --get user.email` to check config is working
# default
[user]
name = wangke
email = wangkest@qq.com
# specific for working
[includeIf "gitdir:/Users/wangke/working/"] # 末尾加斜杠
path = ~/.gitconfig_58corp
# specific for working2
[includeIf "gitdir:/Users/wangke/working/2/"] # 末尾加斜杠
path = ~/.gitconfig_58corp2
|
然后配置刚才指定的配置文件
vim .gitconfig_working
1
2
3
|
[user]
name = working_name
email = working_name@working_name.com
|
vim .gitconfig_working2
1
2
3
|
[user]
name = working_name2
email = working_name2@working_name.com
|
然后在已配置路径下的~/这个路径下使用私人账号/
或者~/这个路径下使用工作账号/
执行命令, 可发现可以自动选择用户了
1
2
|
cd ~/该路径下使用私人账号/
git config --get user.email
|
refs