Before going to configure Git Username and Email Address let’s understand the definition of git. Git is a distributed version control program. Many developers and companies are using it to manage their code version locally or on the server. When while installing git we put git username and email address. When you make any commit, git associate your identity.
You can setup your username and email address as global or per-project as well. To make this kind of change we need to git config command. Using this command, we can either change identity globally or per project. But these changes will only affect your future commits. The commits you have already done will be the same as before, which means those will show with your old identity.
Setup Git Username and Password Globally
This global git username and password identity is connected with all the commits on your repo. Those are on your system that doesn’t have repo specific values.
When you want to change the identity globally you need to run the
git config command with
git config --global user.name "Your Identity Name" git config --global user.email "[email protected]"
When done, you can check your information by the below command.
git config --list
user.name=Your Identity Name [email protected]
Any changes that have been made will be stored in the global configuration file. It exists in the user’s home directory that you can access from here
[user] name = Your Identity Name email = [email protected]
You can also edit this file directly with help of any file editor, but it’s not best practice. You should use the
git config command.
Read Also: How to Change Remote URL in Git?
Setup Git Username and Password for a Particular Repository
When you want to use a different identity for any particular repository you need to use the same command
git config we run before but just without
--global option from that repo directory.
As an example, if you want to change any specific repository code identity stored in
~/myproject/mycode directory just change directory to this repo directory by issuing the command.
Now, setup Git user.name and email address.
git config user.name "My New Name" git config user.email "[email protected]"
Check the information by issuing the below command.
git config --list
user.name=My New Name [email protected]
This repo specific information is in the .git/config file that exists in the code repo root directory.
You have seen how we have setup Git username and email address with
git config command as this is important to figure out the changes made by the developer.
So this is good practice to keep your git config with your identity as it helps to find the changes made by you.
Comment below if you hit any snag or any suggestions.