Cyberithub

How to Configure Git Username and Email Address in 2 Simple Steps

Advertisements

In this article, we will see how to configure Git Username and Email Address in 2 Simple Steps. If you are using Git Repo from long time then you might be aware that Git requires an email address and user name for every commit. If you forget to set these parameters then git won't allow you to commit your changes and it will show some error on the output. Git never verifies the email address and user name given in the configuration so a user can provide any meaningful email address and user name just to track the changes done through that specific ID.

The purpose of asking these information is to add metadata information like who committed some specific changes in the repository. This will be much helpful when someone is reviewing all the commits and want to check what are all the changes done in repository and by whom. Otherwise without this information, it will be very difficult to track the changes done inside repository. More on Github docs.

How to Configure Git Username and Email Address in 2 Simple Steps

How to Configure Git Username and Email Address

Also Read: 3 Best Ways to List all the changed files After Git Commit

Step 1: How to Configure Git Username

To set global Git username, you need to use git config --global user.name "Your Name" syntax as shown below.

[root@localhost ~]# git config --global user.name "cyberithub"

If you don't want to set it globally then you also have the option to set user name per repository. In that case you need to go inside the cloned repository or project directory and use git config command without --global option.

[root@localhost ~]# git config user.name "cyberithub"

To verify if the global username is set or not, you can use git config --list command as shown below. Project wise configuration can be checked from .git/config file present under the project root directory.

[root@localhost ~]# git config --list
core.repositoryformatversion=0
core.filemode=true
core.bare=false
core.logallrefupdates=true
credential.https://source.developers.google.com.helper=gcloud.sh
user.email=cyberithub@gmail.com
user.name=cyberithub
core.repositoryformatversion=0
core.filemode=true
core.bare=false

 

Step 2: How to Configure Git Email Address

To set global Git username, you need to use git config --global user.email "Email ID" syntax as shown below.

[root@localhost ~]# git config --global user.email "cyberithub@gmail.com"

Here also, if you don't want to set email as global Email Address for all the projects and are looking to use separate email for every project. Then you need to go inside the cloned repository or project directory path and set email address without --global option.

[root@localhost ~]# git config user.email "cyberithub@gmail.com"

Like the previous step, to verify if the global email is set or not, you can use same git config --list command as shown below. All the project wise configuration will be available in .git/config file under project root directory.

[root@localhost ~]# git config --list
core.repositoryformatversion=0
core.filemode=true
core.bare=false
core.logallrefupdates=true
credential.https://source.developers.google.com.helper=gcloud.sh
user.email=cyberithub@gmail.com
user.name=cyberithub
core.repositoryformatversion=0
core.filemode=true
core.bare=false

You can also check the git user information from .gitconfig file available under user home directory i.e ~/.gitconfig

[root@localhost ~]# cat ~/.gitconfig
[user]
email = cyberithub@gmail.com
name = cyberithub

Leave a Comment