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

GitGithub

Git Problem Overview


I'm currently working on 2 projects, which expect that I configure my local username and email with different data when I push to them.

for that I'm updaing my config all the time like:

git config --local user.email "[email protected]"

Since they are different repositories, is there a way I could define an local email for each repository?

Maybe in the .gitconfig?

Git Solutions


Solution 1 - Git

For just one repo:

git config user.name "Your Name Here"
git config user.email [email protected]

For (global) default email (which is configured in your ~/.gitconfig):

git config --global user.name "Your Name Here"
git config --global user.email [email protected]

Solution 2 - Git

You can confirm that by printing on the terminal:

  1. Global user:git config --global user.name
  2. Local user: git config user.name

Solution 3 - Git

I generally tend to keep diff name/email for my company project and personal project(on github)

Run below command in the git repo where you need to specify the user/email

git config user.name <user-name>
git config user.email <user-email>

Solution 4 - Git

...or just edit the .git\config file and add these three lines somewhere:

[user]
	name = YourName
	email = [email protected]

Solution 5 - Git

One trick that has been reliably working for me is to set both a global config credential.username option as well as a local one. They will ask for a password for authentication. This works even for Git Credential Manager say on a Mac. For more information, please see: https://docs.github.com/en/get-started/getting-started-with-git/caching-your-github-credentials-in-git. So you can cache like at least two different passwords for two different GitHub accounts.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionPabloView Question on Stackoverflow
Solution 1 - GitgregoryView Answer on Stackoverflow
Solution 2 - GitalvaroIduView Answer on Stackoverflow
Solution 3 - GitGPuriView Answer on Stackoverflow
Solution 4 - Gitt3chb0tView Answer on Stackoverflow
Solution 5 - GitKris SternView Answer on Stackoverflow