4

Suppose I am using a shared computer account and working on a repository with multiple branches, each branch developed by a different user on that same computer account. It would be helpful to not have to switch the user.name and user.email every time a different user uses the computer to make commits to the repository.

How do I set a different user.name and user.email for each branch?

Flux
  • 9,805
  • 5
  • 46
  • 92

2 Answers2

3

The usual approach is to:

  • not rely on a local configuration to the repo
  • rely only on the global configuration (the one in $HOME/.gitconfig)

That way, each user naturally has his/her own user.name/user.email whenever he/she does any commit in a shared repo.

If you really need to only update a branch per user, you could add a pre-commit hook making sure the right branch is about to be committed.

If you are using the same computer account:

a/ don't ;) It is not a best practice to share account
b/ setup an alias (one per user) which would setup that config

One approach that might work is:

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
1

Make a clone for each of you. Run git config --local user.name xxx and git config --local user.email xxx@yyy.zz in each clone. --local can be omitted since it's the default.

But why not create an account for each of you in the same computer?

ElpieKay
  • 27,194
  • 6
  • 32
  • 53
  • I suspect the answer to your question may be of a programmatic nature? A script may run git commands on behalf of a synthetic user as this user may not exist on the native OS -only in the "script-verse". –  Nov 22 '18 at 10:35