Can I specify multiple users for myself in .gitcon

2018-12-31 16:57发布

In my ~/.gitconfig, I list my personal email address under [user], since that's what I want to use for Github repos.

But, I've recently started using git for work, too. My company's git repo allows me to commit, but when it sends out announcements of new changesets, it says they are from Anonymous because it doesn't recognize the email address in my .gitconfig - at least, that's my theory.

Is it possible to specify multiple [user] definitions in .gitconfig? Or is there some other way to override the default .gitconfig for a certain directory? In my case, I check out all work code in ~/worksrc/ - is there a way to specify a .gitconfig for only that directory (and its subdirectories)?

标签: git
19条回答
笑指拈花
2楼-- · 2018-12-31 17:44

Since git 2.13, it is possible to solve this using newly introduced Conditional includes.

An example:

Global config ~/.gitconfig

[user]
    name = John Doe
    email = john@doe.tld

[includeIf "gitdir:~/work/"]
    path = ~/work/.gitconfig

Work specific config ~/work/.gitconfig

[user]
    email = john.doe@company.tld
查看更多
登录 后发表回答