Enroll in Selenium Training

We have now successfully learned about various Git Clients and a few common commands in the previous tutorials. Since we have now Installed Git in our system and learned about it, it is time for some practical on Git Bash. We will try to make some changes to the configuration file of Git and set up our credentials using Git Bash. I hope you remember, we will be using Git Bash only for this course. In this tutorial, we will

  • Set Up Default Credentials for Git Config
  • View list of User's Settings of Git Config

Before going on to these sections, we should first understand why we need to make changes to our configuration file as we install Git or start using it for the first time.

Why set up Configuration File in Git?

As we install Git in our system, the configuration file takes default values for some of the fields. This means Git starts by setting the same files for every user. Although many of these values are default and are kept that way, but the personal ones should not. This creates a conflict in the identity of the programmer among the team about which we will see through an example in this section. So when you first start Git, the common default files (that are common to every user) are searched inside the /etc/gitconfig file of the Git. Once these are set, Git has to see the files specific to a particular user. These specific files are available under ~/.gitconfig or ~/.config/git/config file. The specific file includes your username, your name, etc.

Visit your Git Bash and type the following command to see the personal Configuration Settings.

vi ~/.gitconfig

 git_config_directory

Don't worry about the VI editor. We will discuss it while we set up our text editor. Press enter and see your configuration file. Mine is already set to show you. You will not get any value if you have not already set it.

Let see an example to see why we need to set up these values while working on a project. Many people work on one project but the only thing that can identify you is your username or email. If you don't configure these values inside your config file, these values (name and email, etc) are taken randomly. So when you commit any change, this change is reflected along with your username and email which are random and no one will be able to recognize or remember your credentials. This creates a lot of problems in the team. Hence, we should change this config file.

How to Set Up Default Credentials for Git Config?

Set user's UserName in Git Config

The first change that we will be making inside our config file will be changing our username in Git. To change our username, follow these steps.

Open Git Bash in your system. Type the following command with your username:

git config --global user.name "Your UserName"

global_user_name

Note: Since I entered my own username above, that displays Rajora, Harish. Also changing your username will only affect your future commits and none of your past commits.

This will change the user name to the value you gave in the command. Press enter and if nothing happened, the name was changed successfully.

You might get some error which would be self-explained by Git. For example if you forget to put the "." in between user and name, you might get an error like this

global_user_name_error

Set user's Email in Git Config

After executing the above command successfully, we will change our email. Type the following command

git config --global user.email "Your EmailID"

git_global_email_set

It will change the email id in the Git Config to the email id you mentioned in the command.

Note: It is very important to note that we use --global for personal config files while we use --system to make changes to the default file discussed in the above section. This file should be retained as it is.

How to view a list of User's Settings of Git Config?

Once you have set all the values in the configuration file, you can view all the settings also through Git Bash.

View the complete list of setting in Git Config

For that go to Git Bash and type this command.

git config --list

git_config_list

Press enter and you can see all the settings including the ones that we just set up in the above section.

git_config_list

View a particular setting in Git Config

You can also check for a particular setting in the configuration file instead of opening the complete list. To see this follow these simple steps.

In the Git Bash type the following command:

git config --global <key>

git_config_key

<key> here refers to the name of the setting that you want to see. For the example above the key is user.name that we set up in the above sections. You need to remember the key-value exactly as it is. In this example, it is not a username but user.name. If you cannot remember, you can always display the complete list of config files.

Press enter to see the key-value

 git_config_key_value

I here strongly recommend visiting Git Config page about git --config and get your hands dirty on it after reading this tutorial.

Set Up Notepad++ for Git Bash
Set Up Notepad++ for Git Bash
Next Article
Harish Rajora
I am a computer science engineer. I love to keep growing as the technological world grows. I feel there is no powerful tool than a computer to change the world in any way. Apart from my field of study, I like reading books a lot and developing new stuff.
Reviewers
Lakshay Sharma's Photo
Lakshay Sharma

Similar Articles

Feedback