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:
git clone https://git.eclipse.org/r/jgit/jgit cd jgit
Step 2 : To view all the effective configurations for the current Git repository, run the following command:
git config --list
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:
git config user.name git config remote.origin.url
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:
git config user.email firstname.lastname@example.org
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:
git config user.name "John Doe"
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:
git config my.own.config "Whatever I need"
Step 7 : It is also very easy to delete/unset configuration entries:
git config --unset my.own.config