I’m sure you’ve never had to do a search for “fix author git multiple commits”. Right? Well, I’m not going to talk about how to do that fix (ugh it’s a pain…). What I DO have to share is a way to hopefully avoid that mess in the future without any crazy arcane incantations or embracing tedious per-repository authorship edits.

Global Config

A little background – Git supports multiple layers of configuration at system, global, repository, and of course, CLI levels. The nearest config entry wins (system takes lowest priority with CLI highest).

It’s pretty common to simply run “git config –global user.email “me@myself.i” and call it a day. This command updates your global SSH config (located at ~/.gitconfig on Linux) with your preferred email address.

That works if you always use the same email regardless of repository. But if you prefer to keep (for example) personal projects separate from open source contributions, this gets to be a pain as you need to override at least the email config entry per repository.

Override Config

Just like my trick to use a different SSH key for some repositories, we can use built-in git config directives to make this work. Specifically, includeIf permits including config files based on some conditional.

I always check my repositories out under ~/code, and further group related repos together (eg, ~/code/work/{this,that,another}_repo) in subdirectories. It’s pretty simple to check if the current repo is in a specific subdirectory using gitdir. So I just add a .gitconfig to the subdirectory and in my global config add a conditional include for that subdirectory. See below for an example!

One additional trick that I use in tandem with my SSH configuration is to rewrite the git remote URL. This allows me to clone exactly as I normally would, but rewrite the URL with something specific to that project. From there my SSH config handles rewriting it back when actually interacting with the git remote.


Here are my config files, lightly edited:

User configuration

  name = "Jesse Roberts"
  email = "*****@**********.***"

  editor = vim

  defaultBranch = main

  autoStash = true

  default = upstream

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

Subdirectory configuration overrides

  email = work@workplace.tld
  name = "Jesse Roberts"

[url "git@github.com-work:"]
	insteadOf = git@github.com:

[url "git@bitbucket.org-work:"]
	insteadOf = git@bitbucket.org: