• Skip to primary navigation
  • Skip to main content
Sal Ferrarello
  • About Sal Ferrarello
  • Speaking
  • Connect
    Mastodon GitHub Twitter (inactive)
You are here: Home / Computing / Git Work Email

Git Work Email

Last updated on August 14, 2020 by Sal Ferrarello

I use Git in both my personal and professional life. Depending on the context, I want to use different contact information. This is how I set this up on my machine.

My Work Git Config

I have a directory for my work at ~/work/ which contains my work specific Git config (~/work/.gitconfig). It contains

[user]
    email = work-sal@example.com

My Global Git Config

In my global Git config (~/.gitconfig) I have the following.

[user]
    email = party-sal@example.com
    name = Sal Ferrarello
[includeIf "gitdir:~/work/**"]
    path = ~/work/.gitconfig

The first part of my global Git config contains my global (personal) user information but the second part (includeIf "gitdir:~/work/") is where the magic happens.

This is a Git config conditional include, which loads my ~/work/.gitconfig anytime my current directory matches the pattern ~/work/** (i.e. whenever we are in ~/work or a sub-directory of ~/work).

The result is if I create a Git commit inside the ~/work/ directory my work-sal@example.com email address is used but in other directories my party-sal@example.com email address is used.

Sal Ferrarello
Sal Ferrarello (@salcode)
Sal is a PHP developer with a focus on the WordPress platform. He is a conference speaker with a background including Piano Player, Radio DJ, Magician/Juggler, Beach Photographer, and High School Math Teacher. Sal can be found professionally at WebDevStudios, where he works as a senior backend engineer.

Share this post:

Share on TwitterShare on FacebookShare on LinkedInShare on EmailShare on Reddit
Warning! This is a draft, not a finalized post. See full draft disclosure.

Filed Under: Computing, Dev Tips, Draft, Solution Tagged With: Git, gitconfig

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Copyright © 2023 · Bootstrap4 Genesis on Genesis Framework · WordPress · Log in