Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

https://linuxhint.

com/configure-git-username-email-address/

https://linuxize.com/post/how-to-configure-git-username-and-email/

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:

Setting your Git username for every repository on your computer

$ git config --global user.name "user_name"


$ git config --global user.email "user_email@mail.com"

Confirm that you have set the Git username correctly:


$ git config --global user.name
> Mona Lisa

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

Once done, you can confirm that the information is set by running:

$ 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:

The command saves the values in the global configuration file, ~/.gitconfig:

$ 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.

You can also edit the file with your text editor, but it is recommended to use the git config
command.

What if you do not want to change it globally

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


If you want to use a different username or email address for a specific repository, run the git
config command without the --global option from within the repository directory.

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 "user_email@mail.com"

Confirm that you have set the Git username correctly:


$ git config user.name
> Mona Lisa

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:

Verify that the changes were made correctly:

$ git config --list


The above command will show the information straight out.
This information will definitely store in the ‘.git/config’ configuration file (under the root directory
of the repository.), 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.

The repository-specific setting are kept in the .git/config file under the root directory of the
repository.

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.

You might also like