Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git - includeIf hasconfig:remote.*.url not working

Tags:

git

git-config

I want to use two separate GitHub accounts on the same computer so I setup ssh keys for both of them. Both are working fine. I don't want to config my email and name each time I create a new repo so I looked around and found git's "includeIf" section.

I am using git version 2.37.3

These are my config files right now.

~/.gitconfig

[user]
    email = "[email protected]"
    name = "Home"

[includeIf "hasconfig:remote.*.url:[email protected]:*/**"]
    email = "[email protected]"
    name = "Work"

~/.ssh/config

Host github.com-Home
  HostName github.com
  User git
  IdentityFile ~/.ssh/Home

Host github.com-Work
  HostName github.com
  User git
  IdentityFile ~/.ssh/Work

When I clone a repo like git clone [email protected]:Home/repo.git and run git config user.name inside the repo, I get the expected output of Home

However, when I clone a repo for my work account like git clone [email protected]:Work/repo.git and run git config user.name inside the repo, I get Home instead of Work. Running git config remote.origin.url returns [email protected]:Work/repo.git

Any idea of why this isn't working?

like image 508
ntedvs Avatar asked Feb 01 '26 16:02

ntedvs


1 Answers

Of course, the first thing to change is what @LeGEC has already mentioned.

However, there is another additional detail that should be taken care of (which is already done in the question, but I'd like to emphasize it and since I can't comment, I'll post it as an answer for future reference).

The URL specified must have a glob pattern of */** at the end. ** won't be sufficient and thus you might find yourself in a situation where git will not include the additional configuration.

Example:

[email protected]:*/**

instead of

[email protected]:**

This was something I didn't know and thus I was wondering why it didn't work. For me the solution was the question!

like image 139
Simao Gomes Viana Avatar answered Feb 04 '26 07:02

Simao Gomes Viana



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!