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 = [email protected]
[includeIf "gitdir:~/work/*"]
path = ~/work/.gitconfig
$ cat ~/work/.gitconfig
[user]
name = Serious Q. Programmer
email = [email protected]
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 [email protected]:programmerbiz/repo.git
$ cd repo/
$ git config --list | grep user
user.name=Random J. Hacker
[email protected]
user.name=Serious Q. Programmer
[email protected]
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.
What is the output of git config --list --show-origin | grep user
?
You should see where the configurations are defined.
I would like to automatically configure one and only one default [user] for all repos
In this case, remove all the above users configuration and set a single entry in your global config
# Use the `--global` to store it under your user account configuration
# and it will be used as the default for all of your projects unless you
# define it in your local `.git/config`
git config --global user.name <....>
git config --global user.email <....>
----
# For specific project use the `--local` flag (will be stored in your `.git/config`
git config --local user.name <....>
git config --local user.email <....>
The problem is the way you are specifying the gitdir
, I had the same issue, and the path (full or relative) should end with a slash.
You have gitdir:~/work/*
This is how it should look:
[includeIf "gitdir:~/work/"]
path = ~/work/.gitconfig
You can then go to the directory and check if it worked:
cd ~/work
git config --list | grep user
Cheers!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With