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:
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.
Where do these changes get saved? These local configuration changes are saved inside <your repo>/.git/config file.
Also read: