# What is XDG_CONFIG_HOME for exactly?

4 messages from 2015-03-15 to 2015-03-16. Participants: Robert Dailey, Matthieu Moy.
Thread: https://gitlist.dev/t/38817

## Robert Dailey, 2015-03-15 23:37

Subject: What is XDG_CONFIG_HOME for exactly?
Message-ID: <CAHd499CmxwGJeW6gMARhc+cT+r3TK98m+LyyS+eCFXz8qKHrFw@mail.gmail.com>
URL: https://gitlist.dev/e/CAHd499CmxwGJeW6gMARhc%2BcT%2Br3TK98m%2BLyyS%2BeCFXz8qKHrFw%40mail.gmail.com

```
My understanding is that git reads the priority of configuration as follows:

1. <local_repo>/.git/config
2. $HOME/.gitconfig
3. $XDG_CONFIG_HOME/git/config
4. system level git config (not sure exactly where this is; not
relevant to me on Windows)

I have a .gitconfig in Dropbox that I symlink to my home directory on
different platforms. Specifically, I share this gitconfig across
Cygwin/msys on Windows and Ubuntu.

If I can use XDG_CONFIG_HOME to leverage platform-specific settings,
I'd be able to keep platform-agnostic settings in my $HOME/.gitconfig
and put platform-specific settings in $XDG_CONFIG_HOME/git/config and
simply give XDG_CONFIG_HOME a different name on different platforms.

Is this what it was designed for? If not, what would be the best
approach for this? I was thinking of contributing a patch that would
let you specify the name of your git config in the home directory, but
I'm not sure if that is necessary. Something like this:

$HOME/$GIT_CONFIG_FILENAME, where GIT_CONFIG_FILENAME defaults to
".gitconfig" if it is not set or empty.

```

## Robert Dailey, 2015-03-15 23:50

Subject: Re: What is XDG_CONFIG_HOME for exactly?
Message-ID: <CAHd499AGHgBECH9t_EtkwLx7VCx3yVnDS27PteF3zF1xSAG8Yg@mail.gmail.com>
URL: https://gitlist.dev/e/CAHd499AGHgBECH9t_EtkwLx7VCx3yVnDS27PteF3zF1xSAG8Yg%40mail.gmail.com
In-Reply-To: <CAHd499CmxwGJeW6gMARhc+cT+r3TK98m+LyyS+eCFXz8qKHrFw@mail.gmail.com>

```
As a follow-up, I tested the following in my .bashrc:


# Utilize different GIT settings based on platform
if [[ $OSTYPE == 'msys' || $OSTYPE == 'cygwin' ]]; then
    echo 'Using WINDOWS specific git settings'
    export XDG_CONFIG_HOME=.config-windows
else
    echo 'Using LINUX specific git settings'
    export XDG_CONFIG_HOME=.config-linux
fi


This seems to work nicely!! I share my $HOME directory (located in
dropbox) across all platforms so this helps me keep a consistent
environment across all my machines with zero effort.

On Sun, Mar 15, 2015 at 6:37 PM, Robert Dailey <rcdailey.lists@gmail.com> wrote:
> My understanding is that git reads the priority of configuration as follows:
>
> 1. <local_repo>/.git/config
> 2. $HOME/.gitconfig
> 3. $XDG_CONFIG_HOME/git/config
> 4. system level git config (not sure exactly where this is; not
> relevant to me on Windows)
>
> I have a .gitconfig in Dropbox that I symlink to my home directory on
> different platforms. Specifically, I share this gitconfig across
> Cygwin/msys on Windows and Ubuntu.
>
> If I can use XDG_CONFIG_HOME to leverage platform-specific settings,
> I'd be able to keep platform-agnostic settings in my $HOME/.gitconfig
> and put platform-specific settings in $XDG_CONFIG_HOME/git/config and
> simply give XDG_CONFIG_HOME a different name on different platforms.
>
> Is this what it was designed for? If not, what would be the best
> approach for this? I was thinking of contributing a patch that would
> let you specify the name of your git config in the home directory, but
> I'm not sure if that is necessary. Something like this:
>
> $HOME/$GIT_CONFIG_FILENAME, where GIT_CONFIG_FILENAME defaults to
> ".gitconfig" if it is not set or empty.

```

## Robert Dailey, 2015-03-15 23:59

Subject: Re: What is XDG_CONFIG_HOME for exactly?
Message-ID: <CAHd499CPevdk5E-m2U5rWjiaV+zz74+Ev6hvpeLoieVPb8TFtg@mail.gmail.com>
URL: https://gitlist.dev/e/CAHd499CPevdk5E-m2U5rWjiaV%2Bzz74%2BEv6hvpeLoieVPb8TFtg%40mail.gmail.com
In-Reply-To: <CAHd499AGHgBECH9t_EtkwLx7VCx3yVnDS27PteF3zF1xSAG8Yg@mail.gmail.com>

```
Sorry for the continuous updates... it seems I spoke too soon. This
works until you CD into a repository, then none of the settings are
accessible. So yeah, basically I need to make sure I'm using this as
intended... I still don't understand the purpose of the XDG thing.

On Sun, Mar 15, 2015 at 6:50 PM, Robert Dailey <rcdailey.lists@gmail.com> wrote:
> As a follow-up, I tested the following in my .bashrc:
>
>
> # Utilize different GIT settings based on platform
> if [[ $OSTYPE == 'msys' || $OSTYPE == 'cygwin' ]]; then
>     echo 'Using WINDOWS specific git settings'
>     export XDG_CONFIG_HOME=.config-windows
> else
>     echo 'Using LINUX specific git settings'
>     export XDG_CONFIG_HOME=.config-linux
> fi
>
>
> This seems to work nicely!! I share my $HOME directory (located in
> dropbox) across all platforms so this helps me keep a consistent
> environment across all my machines with zero effort.
>
> On Sun, Mar 15, 2015 at 6:37 PM, Robert Dailey <rcdailey.lists@gmail.com> wrote:
>> My understanding is that git reads the priority of configuration as follows:
>>
>> 1. <local_repo>/.git/config
>> 2. $HOME/.gitconfig
>> 3. $XDG_CONFIG_HOME/git/config
>> 4. system level git config (not sure exactly where this is; not
>> relevant to me on Windows)
>>
>> I have a .gitconfig in Dropbox that I symlink to my home directory on
>> different platforms. Specifically, I share this gitconfig across
>> Cygwin/msys on Windows and Ubuntu.
>>
>> If I can use XDG_CONFIG_HOME to leverage platform-specific settings,
>> I'd be able to keep platform-agnostic settings in my $HOME/.gitconfig
>> and put platform-specific settings in $XDG_CONFIG_HOME/git/config and
>> simply give XDG_CONFIG_HOME a different name on different platforms.
>>
>> Is this what it was designed for? If not, what would be the best
>> approach for this? I was thinking of contributing a patch that would
>> let you specify the name of your git config in the home directory, but
>> I'm not sure if that is necessary. Something like this:
>>
>> $HOME/$GIT_CONFIG_FILENAME, where GIT_CONFIG_FILENAME defaults to
>> ".gitconfig" if it is not set or empty.

```

## Matthieu Moy, 2015-03-16 09:31

Subject: Re: What is XDG_CONFIG_HOME for exactly?
Message-ID: <vpqvbi1qodw.fsf@anie.imag.fr>
URL: https://gitlist.dev/e/vpqvbi1qodw.fsf%40anie.imag.fr
In-Reply-To: <CAHd499AGHgBECH9t_EtkwLx7VCx3yVnDS27PteF3zF1xSAG8Yg@mail.gmail.com>

```
> On Sun, Mar 15, 2015 at 6:37 PM, Robert Dailey <rcdailey.lists@gmail.com> wrote:
>> My understanding is that git reads the priority of configuration as follows:
>>
>> 1. <local_repo>/.git/config
>> 2. $HOME/.gitconfig
>> 3. $XDG_CONFIG_HOME/git/config

$HOME/.gitconfig is the traditional Unix location for config files. It
was the only per-user config files in early versions of Git.

$XDG_CONFIG_HOME/git/config is the location following freedesktop's XDG
standard. It has several advantages (you can version and/or share
individual $XDG_CONFIG_HOME/git/ as a whole directory, while it's much
harder to version all ~/.git* files individually for example).

You typically want to use either one or the other.

>> 4. system level git config (not sure exactly where this is; not
>> relevant to me on Windows)

This is relevant if you use a shared machine and your sysadmin wants to
have the same configuration for all users.

> To unsubscribe from this list: send the line "unsubscribe git" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

Robert Dailey <rcdailey.lists@gmail.com> writes:

> As a follow-up, I tested the following in my .bashrc:
>
>
> # Utilize different GIT settings based on platform
> if [[ $OSTYPE == 'msys' || $OSTYPE == 'cygwin' ]]; then
>     echo 'Using WINDOWS specific git settings'
>     export XDG_CONFIG_HOME=.config-windows

You need an absolute directory here:

export XDG_CONFIG_HOME=$HOME/.config-windows

Then, I'd suggest that $XDG_CONFIG_HOME/git/config contains a

[include]
    path = ../../.config-shared/git/config

so that you can factor out common portions of your config file into
.config-shared/git/config and keep machine-specific portions in
~/.config-{windows,linux}.

-- 
Matthieu Moy
http://www-verimag.imag.fr/~moy/

```
