I've read the `git-config` docs and checked SO questsions [here](https://stackoverflow.com/questions/55249773/exporting-entire-git-configuration-to-be-used-with-git-config) and [here](https://stackoverflow.com/questions/61382534/can-i-use-git-config-environment-variable-to-use-a-config-file-for-all-git-comma), but I cannot seem to find an answer.

I am writing a custom tool for Git and I would like to test it. I would like to backup my global and system Git config files and then write to new config files in my tests so I don't override what I already have in place (FYI, I am testing against multiple different portable (locally built) versions of Git both for Linux and Windows in a subdirectory of my project).

My initial thought would have simply been to use `cp`:

```
# Backup the system config file
# NOTE: How do I test this automatically? (I have to enter root password)...
sudo cp ${PREFIX}/etc/gitconfig ${PREFIX}/etc/gitconfig.bak

# Backup the global config file
cp ~/.gitconfig ~/.gitconfig.bak

# DO MY TESTS HERE

# Restore system config file and delete backup
sudo cp ${PREFIX}/etc/gitconfig.bak ${PREFIX}/etc/gitconfig
sudo rm ${PREFIX}/etc/gitconfig.bak

# Restore global config file and delete backup
cp ~/.gitconfig.bak ~/.gitconfig
rm ~/.gitconfig.bak

```

However, I don't see this being done in `t/t1300-config.sh` (as of the time of this writing, the current version of the master repo is v2.32). The closest thing being done that I see is this (lines 2147-2158):

```
test_expect_success 'write to overridden global and system config' '
    cat >expect <<EOF &&
[config]
    key = value
EOF
    GIT_CONFIG_GLOBAL=write-to-global git config --global config.key value &&
    test_cmp expect write-to-global &&
    GIT_CONFIG_SYSTEM=write-to-system git config --system config.key value &&
    test_cmp expect write-to-system
'

```

I don't understand what is going on here. The Git Docs explain `GIT_CONFIG` is an environment variable that can be set to override the `git config` file, but if I enter the above commands in my terminal, no file `write-to-global` or `write-to-system` is created (and these are not functions in the test script either).

Can someone explain how to properly use the `GIT_CONFIG` environment variable and what's the right way to do this in a test script?