Introduction

In our earlier articles on using the GIT version control system, we’ve shown you how to set or change default user name and email and how to set or change the default editor. In this article, we will share some parameters that you may consider setting in your git configuration and we’ll also talk about the hierarchy of the levels of git configuration settings.

To learn how to install git on a Linux system, please do take a look at our article on how to install git on Centos where we’ve covered how to install the git version control system via yum/rpm and also how to install it from source.

 

Levels of git configuration
There are 3 levels of git config; project, global and system.

project: Project configs are only available for the current project and stored in .git/config in the project’s directory. To access the project or repository level git configuration, we execute the ‘git config’ command from within the project directory.

global: Global configs are available for all projects for the current user and stored in ~/.gitconfig. To access the global git configuration, we use the ‘git config –global’ command.

system: System configs are available for all the users/projects and stored in /etc/gitconfig. To access the system git configuration, we use the ‘git config –system’ command.

Related concept:   Finding the Right Type of Web Hosting

After understanding the three levels of git configuration, we’ll now show you how to set some important parameters in the global configuration.

 

Check currently set parameters:
We use the ‘git config –global –list’ command to list the currently set global git configuration parameters.

[[email protected] ~]# git config --global --list
 fatal: unable to read config file '/root/.gitconfig': No such file or directory
 [[email protected] ~]#

Since we are working on a fresh git installation, we do not have any parameters set at the moment.

 

Setting the username and email
Although we’ve talked about this at length in a separate article, we’ll repeat it again here for the sake of completeness.

[[email protected] ~]# git config --global user.name "Sahil Suri"
[[email protected] ~]# git config --global user.email "[email protected]"
[[email protected] ~]#

Let’s run the ‘git config –global –list’ command now to view our newly set parameters.

[[email protected] ~]# git config --global --list
 user.name=Sahil Suri
 [email protected]

As we can observe from the above output, the parameters have been set successfully. Let’s now check the .gitconfig file in our home directory to validate that the user.name and user.email have been added to the file.

[[email protected] ~]# cat ~/.gitconfig
[user]
name = Sahil Suri
email = [email protected]

 

Related concept:   Configuring service unit files for use with systemd

Setting the core editor
We’ve discussed this option as well in a separate article but we will configure it here again in the interest of completeness.

[[email protected] ~]# git config --global core.editor vim
 [[email protected] ~]#
 [[email protected] ~]# git config --global --list
 user.name=Sahil Suri
 [email protected]
 core.editor=vim

 

Setting autocorrect
Git offers a number of commands for managing projects and it’s easy to get confused and mistype some of them if we are in a hurry. Setting autocorrect to 1 will execute the correct git command in case we misspell it.

[[email protected] ~]# git config --global help.autocorrect 1
[[email protected] ~]# git config --global --list
user.name=Sahil Suri
[email protected]
core.editor=vim
help.autocorrect=1

 

Setting color.ui
Color coding command line output can help the output for readable and also assist in debugging. Setting color.ui to auto will allow git to color code some of the information it displays making the information more readable.

[[email protected] ~]# git config --global color.ui auto

Let’s verify the update.

[[email protected] ~]# git config --global --list
user.name=Sahil Suri
[email protected]
core.editor=vim
help.autocorrect=1
color.ui=auto

If git detects that it’s running within a script then it will not color code information making log parsing easier.

Related concept:   Redis DB Install and Few Commands

 

Setting autocrlf
While writing code on the Windows platforms, it will denote new lines with carriage returns. In contrast to this, the Linux platform will interpret new lines as line feeds. Setting autocrlf to true will change carriage returns and line feeds to line feeds only. This is useful when doing cross-platform development.

[[email protected] ~]# git config --global core.autocrlf input

Let’s validate the update by checking the output ‘git config –global –list’ command and displaying the global git configuration file.

[[email protected] ~]# git config --global --list
user.name=Sahil Suri
[email protected]
core.editor=vim
core.autocrlf=input
help.autocorrect=1
color.ui=auto
[[email protected] ~]# cat ~/.gitconfig
[user]
name = Sahil Suri
email = [email protected]
[core]
editor = vim
autocrlf = input
[help]
autocorrect = 1
[color]
ui = auto 

Conclusion

In this article, we discussed the three levels of git configuration and we demonstrated how to set some important parameters so that your experience using git is more comfortable. We hope you found these tips useful and we look forward towards your feedback.