How to Query the existing configuration (Git)

we will look at how we can query the existing configuration and set the configuration values.

Step 1 : We'll use jgit again by using the following command:

Step 2 : To view all the effective configurations for the current Git repository, run the following command:

Step 3 : If we are just interested in a single configuration item, we can just query it by its section.key or section.subsection.key:

Step 3 : Git's configuration is stored in plain text files and works like a key-value storage. You can set/query by key and get the value back. An example of the text-based configuration file is shown as follows (from the jgit repository):

Step 4 : It is also easy to set configuration values. You can use the same syntax as you did when querying the configuration, except you need to add an argument to the value. To set a new email address on the LOCAL layer, we can execute the following command line:

Step 5 : The LOCAL layer is the default, if nothing else is specified. If you require whitespaces in the value, you can enclose the string in quotation marks, as you would do when configuring your name:

Step 6 : You can even set your own configuration, which does not have any effect on the core Git, but which can be useful for scripting/builds, and so on:

Step 7 : It is also very easy to delete/unset configuration entries: