Following this SO post and the linked guidance, I set up a condition configuration like the following...
$ cat ~/.gitconfig
[user]
name = Random J. Hacker
email = RandomJ@hack.er
[includeIf "gitdir:~/work/*"]
path = ~/work/.gitconfig
$ cat ~/work/.gitconfig
[user]
name = Serious Q. Programmer
email = serious.q@programmer.biz
In this way, all of the repositories I do clone when I'm working for Programmer Co. get my @programmer.biz work email address assigned as the default --author
credential; and every random repo I clone to my desktop or /tmp
or ~/.vscode
or wherever gets my super legit @hack.er credential assigned as the author.
Unfortunately, I noticed the following behaviour...
$ git clone git@github.com:programmerbiz/repo.git
$ cd repo/
$ git config --list | grep user
user.name=Random J. Hacker
user.email=RandomJ@hack.er
user.name=Serious Q. Programmer
user.email=serious.q@programmer.biz
Oh no! My @hack.er user is picked up by the business repo!
I would like to automatically configure one and only one default [user]
for all repos without resorting to a bash script. Is there an includeIf.Not
operator, [else]
block syntax, or similar that I can use in ~/.gitconfig
to achieve this? The conditional includes documentation does not appear to support this use case.