Git Config Per Worktree: Set User Email for One Agent
Prepared and checked using AI. Sources are linked in the article.
To set a Git user.email per worktree, enable extensions.worktreeConfig and write the value with git config --worktree from the agent’s checkout. Set user.name there too if that checkout needs a different name. The setting belongs to that worktree, so another agent’s worktree can use its own identity.
A plain git config user.email ... is the easy mistake. Git writes repository-local configuration to a file shared by the worktrees, so that command can change the email seen in every checkout attached to the repository. Worktree-specific configuration uses a separate config.worktree file for each checkout. If you are new to how the checkouts share a repository, see Git worktrees explained.
Configure one agent worktree
Before enabling the extension, inspect shared core.worktree and core.bare values from an existing checkout of the repository:
git config --local --get core.worktree
git config --local --get core.bare
A missing value produces no value to move. If core.worktree is present, or core.bare is true, follow the worktree configuration section to move that setting from the shared config to the main worktree’s config.worktree as part of enabling the extension. Complete that migration before using the setup below. Review shared sparse-checkout settings as well. Older Git versions refuse to access a repository with this extension, so check the Git versions used by other processes that must open the same repository.
For example, suppose ../agent-review is the agent’s checkout, agent/review is its branch, and you+agent-review@example.com is the email you want on its commits. Create the worktree if it does not already exist, enable the extension once for the repository, and set the identity in the target checkout:
git worktree add -b agent/review ../agent-review
git config --local extensions.worktreeConfig true
git -C ../agent-review config --worktree user.name "Your Name"
git -C ../agent-review config --worktree user.email "you+agent-review@example.com"
Run the first two commands from an existing checkout of that repository. If the agent worktree already exists, skip git worktree add. Git’s -C option runs a command as though it started in the named directory; it makes the target of each write explicit without changing your shell’s directory. You can instead enter the agent worktree and omit -C ../agent-review.
The extension is repository-wide, while each --worktree write targets only the checkout where that command runs. Set a different email in a sibling checkout by running the same command with that sibling’s path. Leave a checkout without a worktree-specific value if it should inherit its existing repository or global identity.
Check both the stored value and the commit identity
First ask Git where the selected email came from in the agent checkout and in another checkout:
git -C ../agent-review config --show-scope --show-origin --get user.email
git config --show-scope --show-origin --get user.email
Run the second command from the other checkout you want to compare. The first output should identify worktree as the scope and point to that checkout’s config.worktree file. The other checkout should report its own effective value and origin. --show-scope and --show-origin are more useful here than reading a guessed .git path: a linked worktree’s .git entry points to Git’s administrative directory elsewhere.
Then check the identities Git would use for a commit in the agent checkout:
git -C ../agent-review var GIT_AUTHOR_IDENT
git -C ../agent-review var GIT_COMMITTER_IDENT
These variables show the author and committer identities. If either identity differs from the expected user.name or user.email, inspect the values and origins of the separate author and committer settings:
git -C ../agent-review config --show-scope --show-origin --get author.name
git -C ../agent-review config --show-scope --show-origin --get author.email
git -C ../agent-review config --show-scope --show-origin --get committer.name
git -C ../agent-review config --show-scope --show-origin --get committer.email
author.name, author.email, committer.name, and committer.email can set those identities independently of user.name and user.email. If those look right or are unset, inspect the environment that launches the agent: Git’s author and committer environment variables can also override the configured identity. The agent must run its Git commands in the intended worktree for that worktree’s configuration to apply.
Choose the scope that matches the job
| Where you set it | Effect for this repository |
|---|---|
git config --global user.email ... | Sets a user-level fallback across repositories and their worktrees. |
git config --local user.email ... | Writes to the repository config shared by its worktrees. |
git config --worktree user.email ... | Writes to the current checkout’s config when extensions.worktreeConfig is enabled. |
git -c user.email=... commit ... | Supplies a value for that one Git command. |
The distinction matters for agent workflows. Use --worktree when a particular checkout needs a persistent identity across several commands. Use git -c for a deliberate one-command override. If you want every new checkout in a directory to receive the same identity automatically, a conditional include may be a better fit.
A worktree setting follows the checkout, not the branch name. Switching the branch in that directory leaves its worktree configuration in place; checking out the branch in a different worktree gives it that other worktree’s configuration. If your rule should follow the branch name instead, Git supports an includeIf "onbranch:..." condition.
Apply one rule to a directory of agent worktrees
The worktree-location condition for includeIf arrived in Git 2.56. The includeIf "worktree:..." example below requires Git 2.56 or newer. On older Git, use the per-checkout --worktree approach above.
For worktrees grouped under a directory, put a conditional include in your global Git configuration. For example, this sample in ~/.gitconfig selects an identity file for checkouts below ~/src/agent-trees/:
[includeIf "worktree:~/src/agent-trees/"]
path = ~/.config/git/agent-trees.inc
The referenced file can contain:
[user]
name = Your Name
email = you+agents@example.com
The trailing slash makes the condition match the directory’s contents. A worktree: condition matches the directory containing checked-out files; gitdir: matches Git’s administrative directory, which is elsewhere for a linked worktree. The worktree: match uses the resolved real path, so a pattern written with a symbolic-link path may miss. Check the result with --show-origin in a checkout under that directory.
This approach applies by location across repositories, while --worktree stores a choice for one checkout in one repository. Configuration is read in order: a value in the shared repository config can override a value included from global config, and a worktree-specific value overrides both. If a conditional include seems ineffective, inspect the effective value’s scope before changing the pattern.
Fix a setting that reached the wrong worktrees
If git config --worktree appears to change siblings, check whether the extension was enabled before the write:
git config --local --get extensions.worktreeConfig
git -C ../agent-review config --worktree --get user.email
git config --local --get user.email
Without the extension, --worktree behaves like --local and writes the shared repository config. In that case, enable the extension, set the intended email in the agent checkout, and review whether the shared user.email should remain as a fallback for the other worktrees. Inspect it before removing it; a shared value may be intentional.
To stop overriding an email in one worktree, remove that checkout’s value:
git -C ../agent-review config --worktree --unset user.email
Git will then select an available value from a lower configuration scope. --unset returns an error if that worktree had no such setting, so confirm its presence with --worktree --get when diagnosing an unexpected result. Repeat the check for user.name if you set both. For broader agent isolation beyond Git identity, see using multiple AI coding agents on one repo.
Where Parallel Code fits
Our product, Parallel Code, is a free, open-source desktop app for macOS and Linux that runs AI coding agents in parallel, each in its own Git worktree. You can apply the worktree configuration above to each agent’s checkout before it makes commits, then use Parallel Code’s diff-first review surface to review their changes.
Frequently asked questions
Why did git config --worktree change every worktree?
Check extensions.worktreeConfig first. When it is disabled, --worktree uses the shared local repository config, so the write is visible in sibling worktrees.
Can I change only the email and keep my usual name?
Yes. Set only user.email with --worktree; Git can take user.name from the shared repository or global config. Check both author and committer identities with git var before the agent commits.
Does a separate user.email give the agent separate push credentials?
No. user.name and user.email supply commit identity fields; authentication credentials are a separate Git concern. Configure access to the remote separately if an agent needs different credentials.
Will this setting follow the branch to another worktree?
No. config.worktree belongs to its checkout, even when that checkout switches branches. Set the value in the new checkout too, or use a conditional include if the rule should follow a path or branch pattern.