DEV Community

Shinji NAKAMATSU
Shinji NAKAMATSU Subscriber

Posted on

1

Use a different git config for each directory using conditional include

It is possible for git to use different config references depending on specific conditions.

This was made aware to me by a question in an earlier post. (Thanks to @francoislp asked this question).

For example, if you have a working directory cloned under the ~/work/ directory and want to use the following configuration:

Add a conditional Include to ~/.gitconfig like this:

[includeIf "gitdir:~/work/**"]
        path = ~/work/.gitconfig
Enter fullscreen mode Exit fullscreen mode

Then put the following in ~/work/.gitconfig

[user]
        name = Foo
        email = foo@example.com
Enter fullscreen mode Exit fullscreen mode

Then, for commits in the working directory under ~/work, the commit will be logged as Foo <foo@example.com>.

As follows:

contrast of execution results

See also

Postmark Image

Speedy emails, satisfied customers

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay