KKAIROS
Practical guideIllustrative3 min read

Git Config Get: read one setting

git config --get KEY prints the value of one setting (the current docs write this as git config get KEY). The recorded Git is 2.34.1. For a key that is not set it exits with status 1; the docs say get "Returns error code 1 if key is not present". This run uses the --get form and shows 1. git config KEY VALUE is the older form of git config set KEY VALUE and writes a value into the repository configuration.

Published:

Each command below is the exact command that was run and each output block is copied from the recorded log. Test ids, log hashes and exit statuses are in the evidence table.

TE-91-A: config sets a value, --get reads it, and --get of an unset key exits with status 1

Setup for this run, inside a throwaway directory (mktemp -d):

git init -q .
git symbolic-ref HEAD refs/heads/main
git config user.email test@example.invalid
git config user.name tester
git config commit.gpgsign false

Command:

git config demo.name demo; git config --get demo.name; echo rc=$?; git config --get demo.missing; echo rc=$?

Recorded output:

demo
rc=0
rc=1

Exit status: 0. The output matches the expected text written before the run.

TE-91-B: git config --unset removes a setting, and --get then exits with status 1

Setup for this run, inside a throwaway directory (mktemp -d):

git init -q .
git symbolic-ref HEAD refs/heads/main
git config user.email test@example.invalid
git config user.name tester
git config commit.gpgsign false
git config demo.name demo

Command:

git config --unset demo.name; echo rc=$?; git config --get demo.name; echo rc=$?

Recorded output:

rc=0
rc=1

Exit status: 0. This status and the output match what was written before the run.

TE-91-C: expected non-zero exit: git config --get with a key that has no section prints an error and exits with status 1

Setup for this run, inside a throwaway directory (mktemp -d):

git init -q .
git symbolic-ref HEAD refs/heads/main
git config user.email test@example.invalid
git config user.name tester
git config commit.gpgsign false

Command:

git config --get bad

Recorded output: none, standard output was empty.

Standard error from the same run:

error: key does not contain a section: bad

Exit status: 1. This status and the output match what was written before the run.

Reading the recorded output

The first read prints demo, the value just written to demo.name, and rc=0 is the exit status of that read. The second read asks for demo.missing, a key that was not set. It prints nothing and gives rc=1. In this run the exit status, not the output, is what reports the missing key.

TE-91-B: by the setup, demo.name was set. --unset exited with status 0, and --get demo.name after it exited with status 1 and printed nothing. TE-91-C: git config --get bad exited with status 1, and standard error reads error: key does not contain a section: bad.

Ad

Limits

Only the repository configuration file was used. The recorded Git is 2.34.1. Global and system files were not tested.

Source

Evidence table

| Test | What it checks | Exit | Verdict | Log sha256 (first 12) | |---|---|---|---|---| | TE-91-A | config sets a value, --get reads it, and --get of an unset key exits with status 1 | 0 | PASS | e81702f4407a | | TE-91-B | git config --unset removes a setting, and --get then exits with status 1 | 0 | PASS | 2c6a514e31f8 | | TE-91-C | expected non-zero exit: git config --get with a key that has no section prints an error and exits with status 1 | 1 | PASS | 42ec4feb861d |

Recorded on: bash 5.1.16(1)-release; git version 2.34.1; Python 3.10.12. Locale C.UTF-8, TZ=UTC. Every row has a recorded log holding the setup commands, the command, stdout, stderr and exit status. The first 12 characters of the log's sha256 are in the table.

All full guides: All guides