Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git user depending on remote url

Tags:

git

I would like to use different user.name/user.email in git depending on remote url. I've tried with gitlab and gitea instances without success.

I've tried to use includeIf following documentation.

~/.gitconfig

[includeIf "hasconfig:remote.*.url:https://git.example.com/**"]
    path = ~/.gitconfig-git.example.com

~/.gitconfig-git.example.com

[user]
    email = [email protected]
    name = Admin

Inside a git repository, I am unable to get the user.

> git config --get remote.origin.url
https://git.example.com/organisation/repository
> git config --get user.email
> git config --get user.name

What am I doing wrong ?

like image 730
Bhasher Avatar asked Jul 03 '26 02:07

Bhasher


1 Answers

I mentioned the 2.36 hasconfig:remote.*.url: new setting as a new value for the conditional inclusion mechanism of configuration files using "[includeIf <condition>]"

That means, if your Git is not at 2.36, said new condition value would just be ignored.


Marcos Pereira suggests in the comments:

Even after updating Git, it took some trial and error to get it to match GitLab SSH URLs.
For those looking for that, this is the pattern that worked for me:

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

**/** also worked, any other combination I tried didn't.

like image 143
VonC Avatar answered Jul 05 '26 22:07

VonC



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!