In Conditionally setting your gitconfig, Marcus Crane solves a problem that many of us have: Different git configuration for personal and work projects. His solution includes adding conditional configuration, like so:

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

I’ve been taking a different approach. According to the git-scm configuration page, git looks for system configuration first, the the user’s personal configuration (~/.gitconfig or ~/.config/git/config), and then the project’s specific configuration.

In my personal configuration, I typically set my name, but don’t set my email.

  name = Ylan Segal

On first interaction with a repository, git makes it evident that an email is needed:

$ git commit
Author identity unknown

*** Please tell me who you are.


  git config --global ""
  git config --global "Your Name"

to set your account's default identity.
Omit --global to set the identity only in this repository.

fatal: no email was given and auto-detection is disabled

I then use git config "ylan@...." to set a project-specific email. I don’t use the --global option. I want to make that choice each time I start interacting with a new repo.

As they say, there are many ways to skin a cat.