Skip to main content
← back to field notes
5 min readDevelopment

Three of me in one git log: keeping identities apart with includeIf

gitadvanced-gittutorialsecuritysshtools

I have been writing in some form or another for thirty years. The current version of this site is controlled in git and I've made commits under three different email addresses. Git never asked which one I meant to use, because git doesn't care. It stamps each commit with whatever user.email it finds and moves on.

On a personal blog that's untidy and nobody's hurt. In a client's repo, or your employer's, the wrong address ends up in their history, and a shared branch isn't yours to rewrite. Git has a feature for this called conditional includes, and one extra setting that makes it refuse to guess.

If you want to count yourself in one of your own repos, this is the command:

git log --format='%ae' | sort | uniq -c | sort -rn

Two of my three are addresses I typed into git config at some point. From September 2023 to April 2026, the log goes back and forth between them. The third is GitHub's noreply address. I'll come back to that one, because it didn't come from my machine at all.

I'm not a contractor. I have a day job and a pile of side projects (some I might even get back to someday...), so for me this is two or three identities. If you work for several clients from one laptop, you've got the same problem with more ways to get it wrong and a contract attached. The setup is the same either way.

Sort your repos into folders by who they're for​

Everything else depends on this:

~/work/
acme/
billing-api/
web/
globex/
platform/
~/personal/
dotfiles/

One folder per client or employer, and every repo for them goes inside it. Personal projects get a folder too.

Give each folder a config file​

Make a small file for each one. This is ~/.gitconfig-acme:

[user]
name = Ris Adams
email = ris.adams@acme.example
signingkey = ~/.ssh/acme_ed25519.pub

[core]
sshCommand = ssh -i ~/.ssh/acme_ed25519 -o IdentitiesOnly=yes

Don't skip the sshCommand line. Without IdentitiesOnly=yes, SSH offers the server every key your agent is holding, and the host signs you in as whichever account matches first. You can have the right email on the commit and still push it as your Globex account.

Load it with includeIf​

Now point your main ~/.gitconfig at those files:

[user]
name = Ris Adams
email = ris@example.com

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

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

Three things go wrong here, and none of them prints an error. Git quietly uses your default.

The trailing slash matters. gitdir:~/work/acme/ matches every repo under that folder, however deep. Drop the slash and it matches none of them.

Order matters too. Git reads the file top to bottom and the last value wins, so the includes go below your default [user] block. Put them above it and your default overrides every one.

On Windows, write gitdir/i: and use forward slashes in the path. Windows treats C:\Users and c:\users as the same folder. Git's pattern match doesn't, so a path typed in the wrong case never matches. The /i makes it case-insensitive.

If one client's repos are scattered all over your disk, you can match on the remote URL instead. This needs git 2.36 or newer:

[includeIf "hasconfig:remote.*.url:git@github.com:acme-corp/**"]
path = ~/.gitconfig-acme

Make git refuse to guess​

That setup still has a default, and the default is how the wrong address gets in. Clone a client's repo into ~/Downloads for a quick look, fix a typo while you're there, and you've committed as your personal self.

You can take the default away:

[user]
name = Ris Adams
useConfigOnly = true

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

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

There's no email in the main file now. A repo outside your known folders has no identity, and with useConfigOnly on, git stops instead of guessing:

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

It's a small annoyance, but a great safety-net. It's also the one place git will tell you something's wrong before the commit exists.

Check which identity you're using​

Inside any repo:

git config --show-origin user.email

You get the email and the file it came from. If you're in a client's folder and the answer came from your main ~/.gitconfig, the include didn't match. Check the slash, then the path.

Keep HTTPS logins apart too​

For clients on HTTPS instead of SSH, the credential helper stores one login per host by default. Two clients on github.com will fight over that one entry. Tell the helper to store a login per repo path:

git config --global credential.https://github.com.useHttpPath true

Git Credential Manager can also hold several accounts for one host. It asks which one to use the first time.

Sign with the right key​

Some clients require signed commits. The signing key is already in each client's file, so the rest can go there as well:

[gpg]
format = ssh
[commit]
gpgsign = true

Acme's repos now get commits signed with Acme's key, and nobody else's repos do.

The website ignores all of this​

Back to that third address in my log. Of those 198 commits, 190 were written by GitHub: 166 pull requests merged with the button, and the rest edited in the browser. GitHub creates those commits itself and uses the email on your account. Your local config never gets a say.

So if you merge or edit through a client's GitHub org, look at Settings › Emails on the account you're signed in as. That address is the one going into their history.

If the wrong one's already pushed​

You can't fix it on a shared branch without a force-push, and in someone else's repo that isn't your call. Tell them. It's a short, slightly embarrassing message, and it beats them finding it first.

In a repo you own, a .mailmap file at the root tidies up the display without touching history:

Ris Adams <ris@example.com> <old-address@example.com>

git shortlog and git log then show the first address wherever the second one appears. The commits themselves still carry the old one.

Does your git client respect any of this?​

Everything above is plain git, so any tool that runs your installed git follows it. Some clients don't. They bundle their own git library or keep their own account profiles, and those can skip your includes or commit as someone else. Before you trust one with client work, open a repo in each folder and read the name it says it'll commit as.

That's one reason Git Revenge, the client I build, shells out to the git you already have. includeIf, sshCommand, credential helpers and signing behave in the app the way they do in a terminal.

The commit form shows who you're about to commit as. Click change next to the name and the Git Config tab opens at the file that sets it, with the row highlighted. If that's your main config when you expected the client's, you find out before the commit instead of after. The tab also lists every file pulled in by [include] and [includeIf], tags each inherited value with where it came from, and backs a file up before saving it.

Two smaller things help when your week is split across clients. A project group per client gets a dashboard with each repo's branch, uncommitted changes and last fetch. Ticket links can be saved in a repo's own config, so ACME-1234 opens Acme's Jira and not someone else's.

If a contract says client code can't go to outside services, there's nothing to switch off. The app has no accounts, telemetry or AI features to begin with.

It has two gaps here. There's no profile switcher beyond git's own config, so the folder layout above is how you do it. And it doesn't scan for secrets, so keep each client's pre-commit hooks in place. The app runs them.

The network and privacy notes are short. If a client asks which tools touch their code, you can paste that page into an email.

field notes

you may also enjoy

more from this thread of thought

A free git client for private repos and self-hosted git
Nov 18, 2026

A free git client for private repos and self-hosted git

read more →
Your giant repo is slow because nobody tuned git
Nov 17, 2026

Your giant repo is slow because nobody tuned git

read more →
Introducing Git Revenge, and whether you should use it
Nov 5, 2026

Introducing Git Revenge, and whether you should use it

read more →
The cost of maintaining open source
Oct 27, 2026

The cost of maintaining open source

read more →
Is there a future without AI?
Oct 25, 2026

Is there a future without AI?

read more →
Introducing "Ink and Agency" a skill pack for humans (and claude)
May 18, 2026

Introducing "Ink and Agency" a skill pack for humans (and claude)

read more →
the field notes

recently written