是否可以为不同的文件夹使用不同的.gitconfig文件

是否可以为不同的文件夹使用不同的.gitconfig文件,git,git-config,Git,Git Config,在多个文件夹的根级别是否可以有不同的.gitconfig文件?我对工作存储库和个人存储库使用不同的电子邮件地址,并且很难始终记住在每个存储库上单独设置电子邮件地址 我想要的是如下内容: git/ ├── work/ │ ├── .gitconfig (with user.email set to my work email) │ ├── app1/ │ ├── app2/ └── home/ ├── .gitconfig (with user.email set to my

在多个文件夹的根级别是否可以有不同的
.gitconfig
文件?我对工作存储库和个人存储库使用不同的电子邮件地址,并且很难始终记住在每个存储库上单独设置电子邮件地址

我想要的是如下内容:

git/
├── work/
│   ├── .gitconfig (with user.email set to my work email)
│   ├── app1/
│   ├── app2/
└── home/
    ├── .gitconfig (with user.email set to my home email)
    ├── app3/
    └── app4/

除了“”中提到的答案外,我更喜欢另一种方法:

  • 不要全局设置任何用户配置(no
    git config--global user.xxx
  • 强制Git在第一次提交时询问我是谁。
    :

  • 使用别名设置正确的用户设置。
    在Windows上,我使用:

    doskey gcu=git config user.name "My Name" ^&^& git config user.email my-email-for@work.com
    doskey gcuvc=git config user.name "VonC" ^&^& git config user.email my-email-for@opensource.org
    

当Git问我是谁时,我键入
gcu
gcuvc
,这取决于Git远程回购(工作或开源)的性质

我将此答案标记为有用,因为它可以作为解决方案,但在我看来,对于一个人来说,想使用不同的电子邮件来处理工作和OSS是一件很平常的事情。真的没有内置机制来处理这个问题吗?我觉得这个问题的简单解决方案就是我在问题中详述的那个。我见过其他软件,例如使用这种方法,它工作得很好。我同意。我更喜欢这种方法,因为我想确保我没有混淆这些设置。在git支持读取目录树之前,这似乎是目前最简单的解决方案。这并不是一个很大的负担。
doskey gcu=git config user.name "My Name" ^&^& git config user.email my-email-for@work.com
doskey gcuvc=git config user.name "VonC" ^&^& git config user.email my-email-for@opensource.org