Can I specify multiple users for myself in .gitconfig?

后端 未结 20 2338
无人及你
无人及你 2020-11-22 06:33

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 s

20条回答
  •  伪装坚强ぢ
    2020-11-22 06:56

    With conditional includes in Git 2.13, it is now possible to have multiple user/email coexist on one machine with little work.

    user.gitconfig has my personal name and email. work-user.gitconfig has my work name and email. Both files are at ~ path.

    So my personal name/email applies by default. For c:/work/ dir, my work name/email is applied. For c:/work/github/ dir, my personal name/email is applied. This works as the last setting gets applied.

    # ~/.gitconfig
    [include]
        path = user.gitconfig
    [includeIf "gitdir/i:c:/work/"]
        path = work-user.gitconfig
    [includeIf "gitdir/i:c:/work/github/"]
        path = user.gitconfig
    

    gitdir is case-sensitive and gitdir/i is case-insensitive.

    "gitdir/i:github/" would apply the conditional include for any directory with github in its path.

提交回复
热议问题