Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / DevOps / Git

How to Set a Different Username and Email for Each Repository in Git?

5.00/5 (2 votes)
2 Oct 2022CPOL1 min read 4.2K  
This blog entry explains how to set up a different username and email id for a personal project.

Consider you are working on two different projects, of which one is your personal project which is hosted on GitHub.com and another one is your professional project which is hosted on the corporate cloud.

On the professional project, you might have set your user name and email that is provided by your organization and which should not be used anywhere else.

If you have already configured the organization's username and email globally in git using the git config command, the same username and email will be used for your personal project commits. I personally don't like to use the organization's username and email, instead I will set up a different username and email id for the personal project.

This tutorial explains how to do the same.

We already know the command to set the username and email is "git config". To set the different username and email id to your personal project or each project that you clone is as follows:

git config user.name "<user name>"

git config user.email "<email id>" 

You need to execute the above commands inside the relevant repo directory, as shown below:

Image 1

After you have executed the above commands, the username and email are changed only for this Repo. From now on, git uses the user name and email id configured for this repo for commits and pushes instead of the globally configured username and password.

You can also verify these configuration changes using the below commands:

git config user.name

git config user.email 

Below is the result after execution of the above two commands in my local.

Image 2

Where do these changes get saved? These local configuration changes are saved inside <your repo>/.git/config file.

Image 3

Also read:

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)