How to Use git config Command

Git is a freely available open-source application that is utilized by different operating system users, including Windows. To use this utility, first, the users are required to install and configure Git on their systems. After doing so, Git GUI or Git Bash can assist you in performing the required operation. More specifically, Git bash offers various useful commands with different supported options to work with Git using its command line, and the “git config” command is one of them.

This tutorial will describe the usage of the git config command on Windows.

What is git config Command?

The “git config” command is a convenience function that is utilized to change and set Git basic configuration values.

How to Use git config Command?

Windows users often use the git config command with several options for customizing the working of Git. However, when this command is executed without any parameter or option, it displays the related manual on the terminal.

Syntax
The general syntax of the git config command is provided below:

$ git config [option]

Different Options of git config Command

Here, we have enlisted some most important git config command options along with their description:

Options Description
–global Use a global config file to perform various operations that is accessible for all present users for all projects.
–system Use a system config file to perform operations that is available for all existing users and projects.
–local Use a repository config file only for current projects.
–add Utilize for adding a new variable in Git.
–edit Use to open the editor.
–file Use to config the given file.

Now, let’s discuss the configuration levels of the git config command.

What are the Configuration Levels git config Command?

There are three configuration levels that are equal to the “.gitconfig text file”, such as:

  • local project: These types of configs are only accessible for the current project and saved in the project’s directory name “.git/config”.
  • global: These configs are available for the current users for all projects and saved in the “~/gitconfig” file, which is used to save a per-person configuration.
  • system: These configs are accessible for all the users and projects on the git and saved in “/etc/gitconfig”.

For differentiation, the below-given sections will consider a scenario of setting the username and email in all git configuration levels. So, let’s head towards it.

How to Use git config Command With Local Configuration Level?

In the local configuration level, the “git config” command configures the username and email with the “–local” option. Let’s check out both one by one.

Example 1: Configure Username
To configure the username in the local configuration level, use the “git config” command and add the “–local” option as mentioned below. For instance, we have specified “Linuxhint1” as a local “user.name” in the current project:

$ git config --local user.name "Linuxhint1"

For the verification of the above operation, add the “–get” option with the “user.name” key:

$ git config --get user.name

Below-given output indicates that the username is successfully added to the Git project directory:

Example 2: Configure Email
You can also configure a local email with the same git config command. However, it is required to specify the email address with the “user.email” key:

$ git config --local user.email "nailanawab422@gmail.com"

Next, add the “–get” option with the “user.email” key for verification:

$ git config --get user.email

The given output shows that our email “nailanawab422@gmail.com” is successfully added to the Git project directly:

Want to make changes in the global configuration level of git? Check out the following section!

How to Use git config Command With Global Configuration Level?

When you want to set a username or email for all currently available git users, switch to the global configuration of the git config command.

To understand the stated concept, check out the below-mentioned examples.

Example 1: Change Username
To change the user name in the global configuration level, use the “git config” command and add “–global” option. Here, we have specified “Linuxhint” as our global “user.name”:

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

For verification, use the “–get” option with the “user.name” key:

$ git config --get user.name

The given output indicates that we have successfully set “Linuxhint” as a global user name:

Example 2: Change User Email
To change the user email globally, add the “–local” option with the “git config” command:

$ git config --global user.email "nazmaria58@gmail.com"

In our case, we have specified “nazmaria58@gmail.com” as a global “user.email”:

Now, verify the changed user email by executing the “–get” option with the “user.email” key:

$ git config --get user.email

As you can see, our specified user email is configured:

To perform configuration for overall git system users, step into the system configuration level.

How to Use git config Command With System Configuration Level?

In this example, we will check out the examples of changing the username and email using the “–system” options.

Example 1: Change Username
To change the username for all git users, first, move to the repository using the “cd” command:

$ cd "C:\repository"

After doing so, run the “git config” command with “–system” option:

$ git config --system user.name "Linuxhint2"

Here, we have specified “Linuxhint2” as a git system user:

For verification, utilize the “–get” option with the “user.name” key:

$ git config --system --get user.name

Example 2: Change Email
Run the below-provided command to change the user email using the “–system” option:

$ git config --system user.email "hooriakhan422gmail.com"

Execute the “git config” command with the “–get” option to show the added email:

$ git config --system --get user.email

Let’s check out the usage of “–add” and “–edit” options with the “git config” command.

How to Add a New Variable Using git config Command?

When Windows users require to add a new variable in the Git files without changing the present data, the “–add” option can be utilized with the “git config” command to add without altering any existing values or data.

For instance, we want to add “Its Linuxhint” in our “gitfile.txt” file. For this purpose, run the below-provided command and specify the variable with the “user.gitfile” key:

$ git config --add user.gitfile "Its Linuxhint"

For verification, use the “–get” option with “gitfile.txt” and press “Enter”:

$ git config --get gitfile.txt

How to Open a Text Editor Using git config Command?

Sometimes writing a particular text or message in the terminal becomes difficult. To resolve this issue, we have many choices, including pre-installed editors, such as “vim”, “GNU Nano”, and “Atom”. For Windows “Notepad++” is a highly recommended text editor.

To open the text editor using the “git config” command, add the “–edit” option as follows:

$ git config --edit

As a result, a text editor will open up on your screen, which you have configured during Git installation. For instance, our configured text editor is “Notepad++”:

That’s all! We have effectively described the information related to the usage git config command.

Conclusion

The “git config” command is a function that is used to set and change Git values through three configuration levels: “local”, “global”, and “system”. This command uses multiple options to perform various operations on Git, such as changing the Username and Email via different configuration levels, adding variables, and opening the text editor. In this tutorial, we have demonstrated the usage of the git config command on Windows.



from https://ift.tt/MD6iFTH

Post a Comment

0 Comments