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:
The git will be installed in a moment, and the installation can be verified using the command provided below:
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:
After successfully configuring the username and email address globally, you can view the information about the Git user using the command:
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:
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:
Then, navigate to the newly created project directory.
Once you are in the project’s directory, initialize the git repository using the command:
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:
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:
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:
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.