c
static void set_config_if_exists(const char *key, const char *file_path)
{
    char *value = NULL;
    if (git_config_get_string(key, &value) == 0 && value) {
        if (git_config_set_in_file(file_path, key, value) < 0)
            die(_("Failed to set %s"), key);
        free(value);
    }
}

// Usage
set_config_if_exists("submodule.alternateLocation", p);
set_config_if_exists("submodule.alternateErrorStrategy", p);
