Jae's Blog

2025-04-21

Conditional Git config

Filed under: Random,Tutorials — jae @ 09:34

A little known feature of Git is that you can have conditions, for instance, to have a work and personal name and email.

First, the ~/.gitconfig file:

[includeIf "gitdir:~/src/personal/"]
  path = ~/.gitconfig.personal

[includeIf "gitdir:~/src/work/"]
  path = ~/.gitconfig.work
Code language: PHP (php)

After specifying this, you can then create two files, ~/.gitconfig.personal and ~/.gitconfig.work, containing:

[user]
    email = email@something.com
    name = MyName

and

[user]
    email = jae@consoso.com
    name = Very serious business person

Now, when you are in ~/src/personal/, the personal email and name will be used, and when in ~/src/work/, the work one will be.

No Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URL

Leave a comment

CC BY-SA 4.0 2012-2025 Jae Lo Presti