Git

How to Configure Git Username and Email Address

Git is a popular version control system, and many developers use it for the modern era’s software development. It helps track changes, reverting to previous stages, and branching to create a different software version. This post will help you configure Git and let you know the simplest way to set the Git username and Email address on CentOS 8 operating system.

Prerequisite

This post’s purpose is to just help you in configuring the username and email address of Git on the CentOS 8 Operating system. Make sure Git is installed on your CentOS 8 system. If it is not installed, the command is pretty simple and easy because its latest and stable version is available on CentOS 8’s official package repository, and you can quickly install it from there using the command given below:

$ sudo dnf install git -y

The git will be installed in a moment, and the installation can be verified using the command provided below:

$ git --version

You can witness in the screenshot attached that version 2.8.2 of Git is successfully installed on the CentOS 8 operating system. Now let’s see how to set up the basic configuration of Git for getting started with it.

Now, there can be two possible ways that you want to set up and configure Git, either you want to configure it globally or in a single project. So, let’s go and see how we can configure Git username and Email address globally.

How to Setup Global Configuration of Git on CentOS 8

To change the username and email address of Git globally, the commit messages will have the correct information about the user in every project. We can configure both username and email address using the git config command with the –global flag as shown in the commands given below:

$ git config --global user.name "user_name"
$ git config --global user.email "[email protected]"

After successfully configuring the username and email address globally, you can view the information about the Git user using the command:

$ git config --list

The above command will show the information of the Git user.

This information is stored in the ‘.gitconfig’ configuration file of the Git, and if you want to edit that information, you can use the command provided below and change it to your desire:

$ sudo nano ~/.gitconfig

After changing it as per your desire, save the file and exit using the keyboard shortcut keys CTRL + S and CTRL + X.

What if you do not want to change it globally but only in the project’s directory. Let’s see how we can change Git Username and email address in a single repository.

How to Configure Git in a single Repository

To change the username and email address of Git in a single repository only so that the commit messages inside that repository will have different information about the user.

First, you have to navigate to the directory in which the project is set up or if there is no project directory, create a directory using the ‘mkdir’ command:

$ mkdir projectDirectory

Then, navigate to the newly created project directory.

$ cd projectDirectory

Once you are in the project’s directory, initialize the git repository using the command:

$ git init

the method for configuring both username and email address will be the same using the git config command but without the –global flag as shown in the commands given below:

$ git config user.name "user_name"
$ git config user.email "[email protected]"

This way, you can successfully configure the username and email address of the user inside a single repository; you can view the information about the Git user using the command:

$ git config --list

The above command will show the information straight out.

This information will definitely store in the ‘.gitconfig’ configuration file, and you can edit that information using the command provided below:

$ sudo nano ~/.gitconfig

After changing it as per your desire, save the file and exit using the keyboard shortcut keys CTRL + S and CTRL + X.

Conclusion

This is all about how you can configure and change the username and Email address of the Git user globally and inside a single repository. After reading this post, you can have a different username and email address in every different project.

About the author

Shehroz Azam

A Javascript Developer & Linux enthusiast with 4 years of industrial experience and proven know-how to combine creative and usability viewpoints resulting in world-class web applications. I have experience working with Vue, React & Node.js & currently working on article writing and video creation.