Git
user configuration
local repository
user.name
user.email

Git Set local user.name and user.email different for each repo

Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions

Introduction

Git lets you set user.name and user.email at the repository level, so one machine can use different identities for work, open source, or personal projects. The important part is understanding that local configuration lives inside the repository’s .git/config file and overrides your global defaults only for that repo.

Git Configuration Precedence

Git reads configuration from multiple places, with more specific settings overriding broader ones. For this topic, the relevant levels are:

  • system
  • global
  • local

Local configuration applies only to the current repository. That is what you want when one repo must commit as [email protected] and another must commit as [email protected].

Set a Different Identity for One Repository

Open a shell inside the repository and run:

bash
git config user.name "Alice Developer"
git config user.email "[email protected]"

Because the command is being run inside a Git repository, Git writes these values into the local repository config by default. You can make that explicit if you want:

bash
git config --local user.name "Alice Developer"
git config --local user.email "[email protected]"

After that, new commits in this repository use the local identity instead of the global one.

Verify Which Value Git Will Use

When debugging identity issues, do not guess. Ask Git which value it sees and where it came from:

bash
git config --show-origin --get user.name
git config --show-origin --get user.email

To inspect all matching user settings:

bash
git config --show-origin --get-regexp '^user\.'

This is useful when you suspect a global config, include file, or repo-local override is not what you expected.

Confirm with a Test Commit

You can verify the active author settings before pushing anything important:

bash
git commit --allow-empty -m "Check local identity"
git log -1 --format='%an <%ae>'

If the output shows the expected name and email, the repository is configured correctly. If not, inspect the local config again before continuing.

What File Git Changes

Repository-specific settings are stored in:

text
.git/config

A minimal example looks like this:

ini
[user]
    name = Alice Developer
    email = [email protected]

You normally do not need to edit that file by hand. git config is safer because it preserves formatting and avoids small syntax mistakes.

Local Config Changes Future Commits, Not History

Changing user.name and user.email locally affects future commits only. Existing commits already contain author and committer metadata inside the commit objects. If earlier commits used the wrong identity, fixing the config now will not rewrite them.

For future work, this is enough. For old commits, you would need history rewriting, which is a separate and more invasive operation.

A Good Default Setup

Many developers keep a general personal identity globally and override it only in the repositories that require a different one:

bash
git config --global user.name "Alice Personal"
git config --global user.email "[email protected]"

Then, inside work repositories:

bash
git config user.name "Alice Developer"
git config user.email "[email protected]"

That setup is simple and predictable. It also makes mistakes obvious, because only the special repositories need an override.

Common Pitfalls

The most common mistake is running git config --global when the intention was to change only one repository. That changes the default for every repo on the machine.

Another pitfall is running git config user.name ... outside a Git repository and assuming the current project was updated. If there is no repo context, Git cannot write a local repo config.

It is also easy to forget that existing commits keep their original identity. Changing the config fixes only new commits, not old history.

Finally, do not rely on memory when debugging. Use git config --show-origin so you can see exactly which file is supplying the active value.

Summary

  • Set per-repo identities with git config user.name and git config user.email inside the repository.
  • Local config overrides global config only for that repository.
  • Verify the active settings with git config --show-origin.
  • Repository-local values live in .git/config.
  • Config changes affect future commits, not commits that already exist in history.

Related reading
Free course
Beginner
7 lessons
2 hours
Tackling System Design Interview Problems

A short course that equips you with the skills to approach system design interviews methodically.

Start the free course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions

All Rights Reserved.