# Configuring the location of ~/.gitconfig

14 messages from 2012-09-26 to 2012-09-28. Participants: Ramkumar Ramachandra, David Aguilar, Junio C Hamano, Anurag Priyam, Matthieu Moy, Jeff King.
Thread: https://gitlist.dev/t/31655

## Ramkumar Ramachandra, 2012-09-26 14:14

Subject: Configuring the location of ~/.gitconfig
Message-ID: <CALkWK0nEP2gf4fYL=hjHg_U3X67M4PF1aupV+VJb9T6eBEo0MQ@mail.gmail.com>
URL: https://gitlist.dev/e/CALkWK0nEP2gf4fYL%3DhjHg_U3X67M4PF1aupV%2BVJb9T6eBEo0MQ%40mail.gmail.com

```
Hi,

I'd like to configure the location of ~/.gitconfig through an
environment variable.  My usecase is a simple enough: I have a
repository with all my dotfiles, and I don't want to symlink
~/dotfiles/.gitconfig from $HOME after cloning it.  Does anyone else
think the feature will be useful?

A couple of similar examples:
1. The git templates directory is configurable via the
GIT_TEMPLATE_DIR variable.
2. The location of ~/.zshrc, ~/.zlogin etc is configurable via the
ZDOTDIR variable in ZSH.

Ram

```

## David Aguilar, 2012-09-26 18:34

Subject: Re: Configuring the location of ~/.gitconfig
Message-ID: <CAJDDKr6q1k+nM9VTukLvze2E6wRBrMOHeZRAoAbKp0MbGv4cQQ@mail.gmail.com>
URL: https://gitlist.dev/e/CAJDDKr6q1k%2BnM9VTukLvze2E6wRBrMOHeZRAoAbKp0MbGv4cQQ%40mail.gmail.com
In-Reply-To: <CALkWK0nEP2gf4fYL=hjHg_U3X67M4PF1aupV+VJb9T6eBEo0MQ@mail.gmail.com>

```
On Wed, Sep 26, 2012 at 7:14 AM, Ramkumar Ramachandra
<artagnon@gmail.com> wrote:
> Hi,
>
> I'd like to configure the location of ~/.gitconfig through an
> environment variable.  My usecase is a simple enough: I have a
> repository with all my dotfiles, and I don't want to symlink
> ~/dotfiles/.gitconfig from $HOME after cloning it.  Does anyone else
> think the feature will be useful?
>
> A couple of similar examples:
> 1. The git templates directory is configurable via the
> GIT_TEMPLATE_DIR variable.
> 2. The location of ~/.zshrc, ~/.zlogin etc is configurable via the
> ZDOTDIR variable in ZSH.

There was some work recently to teach git about the XDG_CONFIG_HOME variable.

Would that help, or are the XDG variables too global for your usage?
-- 
David

```

## Junio C Hamano, 2012-09-27 06:09

Subject: Re: Configuring the location of ~/.gitconfig
Message-ID: <7v6270t2tb.fsf@alter.siamese.dyndns.org>
URL: https://gitlist.dev/e/7v6270t2tb.fsf%40alter.siamese.dyndns.org
In-Reply-To: <CALkWK0nEP2gf4fYL=hjHg_U3X67M4PF1aupV+VJb9T6eBEo0MQ@mail.gmail.com>

```
Ramkumar Ramachandra <artagnon@gmail.com> writes:

> I'd like to configure the location of ~/.gitconfig through an
> environment variable.  My usecase is a simple enough: I have a
> repository with all my dotfiles, and I don't want to symlink
> ~/dotfiles/.gitconfig from $HOME after cloning it.  Does anyone else
> think the feature will be useful?

Not me. For that particular use case, my approach (long before I
switched the vcs that controls my dotfiles to git) have always been
to have ~/src that is version controlled, with a Makefile that
builds/adjusts dotfiles appropriately for each box and installs them
in the proper place.

Of course, if .gitconfig _is_ the same across all boxes I use, that
Makefile is likely to "install" by making a symlink ~/.gitconfig
that points at src/dot/gitconfig without "building".

```

## Anurag Priyam, 2012-09-27 06:40

Subject: Re: Configuring the location of ~/.gitconfig
Message-ID: <CAD1m08Wz7WqP8Yxgc6xuhBSntQ0PS6hGOzHWrcd0VAbARmkuUA@mail.gmail.com>
URL: https://gitlist.dev/e/CAD1m08Wz7WqP8Yxgc6xuhBSntQ0PS6hGOzHWrcd0VAbARmkuUA%40mail.gmail.com
In-Reply-To: <7v6270t2tb.fsf@alter.siamese.dyndns.org>

```
On Thu, Sep 27, 2012 at 11:39 AM, Junio C Hamano <gitster@pobox.com> wrote:
> Ramkumar Ramachandra <artagnon@gmail.com> writes:
>
>> I'd like to configure the location of ~/.gitconfig through an
>> environment variable.  My usecase is a simple enough: I have a
>> repository with all my dotfiles, and I don't want to symlink
>> ~/dotfiles/.gitconfig from $HOME after cloning it.  Does anyone else
>> think the feature will be useful?
>
> Not me. For that particular use case, my approach (long before I
> switched the vcs that controls my dotfiles to git) have always been
> to have ~/src that is version controlled, with a Makefile that
> builds/adjusts dotfiles appropriately for each box and installs them
> in the proper place.

Makefile is what I wanted to avoid when I suggested Ram that maybe Git
could _optionally_ read the location of global gitconfig from an
environment variable that can be exported in zshenv or bash_profile.

I don't think either way is the best way of managing dotfiles.  Just a
matter of preference.  The environment variable approach doesn't
require you to run `make` everytime you sync your dotfiles across
different machines, and that is what I like.

Also, Git allows configuring the location of template directory via an
environment variable (GIT_TEMPLATE_DIR).  Since Git has already fixed
the location of global gitconfig, it might as well read the location
of template directory from there (init.templatedir).  Why the added
flexibility?  Well, I have been exploiting the feature to manage git
templates through my zsh configuration.

-- 
Anurag Priyam

```

## Ramkumar Ramachandra, 2012-09-27 06:49

Subject: Re: Configuring the location of ~/.gitconfig
Message-ID: <CALkWK0nYnyaoOsH_x8U96ADZT7VuP-pR36+RRcjTw39Kp1qCnw@mail.gmail.com>
URL: https://gitlist.dev/e/CALkWK0nYnyaoOsH_x8U96ADZT7VuP-pR36%2BRRcjTw39Kp1qCnw%40mail.gmail.com
In-Reply-To: <CAJDDKr6q1k+nM9VTukLvze2E6wRBrMOHeZRAoAbKp0MbGv4cQQ@mail.gmail.com>

```
Hi David,

David Aguilar wrote:
> Would that help, or are the XDG variables too global for your usage?

Yeah, they're too global.  I'll write a patch.

Ram

```

## Ramkumar Ramachandra, 2012-09-27 14:46

Subject: [PATCH] config: introduce GIT_GLOBAL_CONFIG to override ~/.gitconfig
Message-ID: <1348757171-3223-1-git-send-email-artagnon@gmail.com>
URL: https://gitlist.dev/e/1348757171-3223-1-git-send-email-artagnon%40gmail.com
In-Reply-To: <CALkWK0nYnyaoOsH_x8U96ADZT7VuP-pR36+RRcjTw39Kp1qCnw@mail.gmail.com>

```

Signed-off-by: Ramkumar Ramachandra <artagnon@gmail.com>
---
 Documentation/git-config.txt |    3 +++
 path.c                       |    5 +++++
 t/t1306-xdg-files.sh         |    8 ++++++++
 3 files changed, 16 insertions(+), 0 deletions(-)

diff --git a/Documentation/git-config.txt b/Documentation/git-config.txt
index eaea079..c8db03f 100644
--- a/Documentation/git-config.txt
+++ b/Documentation/git-config.txt
@@ -205,6 +205,9 @@ $GIT_DIR/config::
 	User-specific configuration file. Also called "global"
 	configuration file.
 
+$GIT_GLOBAL_CONFIG::
+	Overrides the path of the global configuration file.
+
 $XDG_CONFIG_HOME/git/config::
 	Second user-specific configuration file. If $XDG_CONFIG_HOME is not set
 	or empty, $HOME/.config/git/config will be used. Any single-valued
diff --git a/path.c b/path.c
index cbbdf7d..9b09cee 100644
--- a/path.c
+++ b/path.c
@@ -131,10 +131,15 @@ char *git_path(const char *fmt, ...)
 
 void home_config_paths(char **global, char **xdg, char *file)
 {
+	char *global_config = getenv("GIT_GLOBAL_CONFIG");
 	char *xdg_home = getenv("XDG_CONFIG_HOME");
 	char *home = getenv("HOME");
 	char *to_free = NULL;
 
+	if (global_config) {
+		*global = mkpathdup("%s", global_config);
+		return;
+	}
 	if (!home) {
 		if (global)
 			*global = NULL;
diff --git a/t/t1306-xdg-files.sh b/t/t1306-xdg-files.sh
index 8b14ab1..5b0e08e 100755
--- a/t/t1306-xdg-files.sh
+++ b/t/t1306-xdg-files.sh
@@ -28,6 +28,14 @@ test_expect_success 'read config: xdg file exists and ~/.gitconfig exists' '
 	test_cmp expected actual
 '
 
+test_expect_success 'read config: $GIT_GLOBAL_CONFIG is set and ~/.gitconfig exists' '
+	>.gitconfig &&
+	echo "[alias]" >.gittestconfig &&
+	echo "	myalias = !echo in_gitconfig" >>.gittestconfig &&
+	echo in_gitconfig >expected &&
+	GIT_GLOBAL_CONFIG=~/.gittestconfig git myalias >actual &&
+	test_cmp expected actual
+'
 
 test_expect_success 'read with --get: xdg file exists and ~/.gitconfig doesn'\''t' '
 	rm .gitconfig &&
-- 
1.7.8.1.362.g5d6df.dirty

```

## Matthieu Moy, 2012-09-27 16:57

Subject: Re: [PATCH] config: introduce GIT_GLOBAL_CONFIG to override ~/.gitconfig
Message-ID: <vpq626zjtds.fsf@grenoble-inp.fr>
URL: https://gitlist.dev/e/vpq626zjtds.fsf%40grenoble-inp.fr
In-Reply-To: <1348757171-3223-1-git-send-email-artagnon@gmail.com>

```
Ramkumar Ramachandra <artagnon@gmail.com> writes:

> diff --git a/Documentation/git-config.txt b/Documentation/git-config.txt
> index eaea079..c8db03f 100644
> --- a/Documentation/git-config.txt
> +++ b/Documentation/git-config.txt
> @@ -205,6 +205,9 @@ $GIT_DIR/config::
>  	User-specific configuration file. Also called "global"
>  	configuration file.
>  
> +$GIT_GLOBAL_CONFIG::
> +	Overrides the path of the global configuration file.
> +

I'm not particularly in favor of introducing another environment
variable, but if you are to introduce it, why just override the
configuration file, and not $HOME completely (e.g. to override
$HOME/.git-credentials too).

There was a patch proposing that here ($GIT_HOME to override $HOME):

  http://thread.gmane.org/gmane.comp.version-control.git/135447/focus=135494

I don't remember exactly what happened to the patch, I can't find an
explicit reason to reject it in the thread, but it seems it didn't make
its way to git.git.

> index cbbdf7d..9b09cee 100644
> --- a/path.c
> +++ b/path.c
> @@ -131,10 +131,15 @@ char *git_path(const char *fmt, ...)
>  
>  void home_config_paths(char **global, char **xdg, char *file)
>  {
> +	char *global_config = getenv("GIT_GLOBAL_CONFIG");
>  	char *xdg_home = getenv("XDG_CONFIG_HOME");
>  	char *home = getenv("HOME");
>  	char *to_free = NULL;
>  
> +	if (global_config) {
> +		*global = mkpathdup("%s", global_config);
> +		return;
> +	}

If you return here, haven't you completely broken the XDG stuff, since
*xdg is set a few lines below in the function?

Also, I guess home_config_paths(..., "ignore") will return the path to
the configuration file instead of the ignore file?

> --- a/t/t1306-xdg-files.sh
> +++ b/t/t1306-xdg-files.sh
> @@ -28,6 +28,14 @@ test_expect_success 'read config: xdg file exists and ~/.gitconfig exists' '
>  	test_cmp expected actual
>  '
>  
> +test_expect_success 'read config: $GIT_GLOBAL_CONFIG is set and ~/.gitconfig exists' '
> +	>.gitconfig &&
> +	echo "[alias]" >.gittestconfig &&
> +	echo "	myalias = !echo in_gitconfig" >>.gittestconfig &&
> +	echo in_gitconfig >expected &&
> +	GIT_GLOBAL_CONFIG=~/.gittestconfig git myalias >actual &&
> +	test_cmp expected actual
> +'

You should check that "git config --set" works too, as the codepath for
writing to configuration is relatively different from the one to read.
For example, I *think* that "git config --global" will write to
$GIT_GLOBAL_CONFIG and "git config" without --global will ignore it, but
a test would be welcome.

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

```

## Junio C Hamano, 2012-09-27 17:16

Subject: Re: Configuring the location of ~/.gitconfig
Message-ID: <7vzk4bqtd1.fsf@alter.siamese.dyndns.org>
URL: https://gitlist.dev/e/7vzk4bqtd1.fsf%40alter.siamese.dyndns.org
In-Reply-To: <CAD1m08Wz7WqP8Yxgc6xuhBSntQ0PS6hGOzHWrcd0VAbARmkuUA@mail.gmail.com>

```
Anurag Priyam <anurag08priyam@gmail.com> writes:

>> Not me. For that particular use case, my approach (long before I
>> switched the vcs that controls my dotfiles to git) have always been
>> to have ~/src that is version controlled, with a Makefile that
>> builds/adjusts dotfiles appropriately for each box and installs them
>> in the proper place.
>
> Makefile is what I wanted to avoid when I suggested Ram that maybe Git
> could _optionally_ read the location of global gitconfig from an
> environment variable that can be exported in zshenv or bash_profile.

Where exactly do the "zshenv" and "bash_profile" you mention reside,
and how are their contents kept up to date?  I am guessing it is
/net/srv1/home/ram/.bash_profile on machines that mount user home
directories from srv1 NFS server and it is to have a string like
"export GITCONFIG_FILE=/net/srv1/home/ram/dot/gitconfig" or on those
machines.  The contents of ~ram/dot/gitconfig may be able to stay
the same across boxes, but how is ~ram/.bash_profile is set up?
Manually?

Again, I am not personally interested; I think aversion of Make is
the root cause of the disease.

```

## Junio C Hamano, 2012-09-27 17:27

Subject: Re: [PATCH] config: introduce GIT_GLOBAL_CONFIG to override ~/.gitconfig
Message-ID: <7vvcezqsug.fsf@alter.siamese.dyndns.org>
URL: https://gitlist.dev/e/7vvcezqsug.fsf%40alter.siamese.dyndns.org
In-Reply-To: <1348757171-3223-1-git-send-email-artagnon@gmail.com>

```
Ramkumar Ramachandra <artagnon@gmail.com> writes:

> Signed-off-by: Ramkumar Ramachandra <artagnon@gmail.com>
> ---
>  Documentation/git-config.txt |    3 +++
>  path.c                       |    5 +++++
>  t/t1306-xdg-files.sh         |    8 ++++++++
>  3 files changed, 16 insertions(+), 0 deletions(-)
>
> diff --git a/Documentation/git-config.txt b/Documentation/git-config.txt
> index eaea079..c8db03f 100644
> --- a/Documentation/git-config.txt
> +++ b/Documentation/git-config.txt
> @@ -205,6 +205,9 @@ $GIT_DIR/config::
>  	User-specific configuration file. Also called "global"
>  	configuration file.
>  
> +$GIT_GLOBAL_CONFIG::
> +	Overrides the path of the global configuration file.
> +

Why is this even a good idea?

  - Does it make sense not to read $HOME/.gitconfig or XDG stuff
    when this is set?  Why skip them?  If it makes sense to skip
    them, why doesn't it also skip $GIT_DIR/config and/or
    /etc/gitconfig?

  - Why is it not "the third user-specific configuration file" instead?

  - Why is it not "a list of paths to read configurations from"?

  - Where does it end?

Not overly impressed, I'd have to say.

> diff --git a/path.c b/path.c
> index cbbdf7d..9b09cee 100644
> --- a/path.c
> +++ b/path.c
> @@ -131,10 +131,15 @@ char *git_path(const char *fmt, ...)
>  
>  void home_config_paths(char **global, char **xdg, char *file)
>  {
> +	char *global_config = getenv("GIT_GLOBAL_CONFIG");
>  	char *xdg_home = getenv("XDG_CONFIG_HOME");
>  	char *home = getenv("HOME");
>  	char *to_free = NULL;
>  
> +	if (global_config) {
> +		*global = mkpathdup("%s", global_config);
> +		return;
> +	}
>  	if (!home) {
>  		if (global)
>  			*global = NULL;
> diff --git a/t/t1306-xdg-files.sh b/t/t1306-xdg-files.sh
> index 8b14ab1..5b0e08e 100755
> --- a/t/t1306-xdg-files.sh
> +++ b/t/t1306-xdg-files.sh
> @@ -28,6 +28,14 @@ test_expect_success 'read config: xdg file exists and ~/.gitconfig exists' '
>  	test_cmp expected actual
>  '
>  
> +test_expect_success 'read config: $GIT_GLOBAL_CONFIG is set and ~/.gitconfig exists' '
> +	>.gitconfig &&
> +	echo "[alias]" >.gittestconfig &&
> +	echo "	myalias = !echo in_gitconfig" >>.gittestconfig &&
> +	echo in_gitconfig >expected &&
> +	GIT_GLOBAL_CONFIG=~/.gittestconfig git myalias >actual &&

How is this tilde expanded and by whom?

```

## Jeff King, 2012-09-27 17:35

Subject: Re: [PATCH] config: introduce GIT_GLOBAL_CONFIG to override ~/.gitconfig
Message-ID: <20120927173532.GD1547@sigill.intra.peff.net>
URL: https://gitlist.dev/e/20120927173532.GD1547%40sigill.intra.peff.net
In-Reply-To: <1348757171-3223-1-git-send-email-artagnon@gmail.com>

```
On Thu, Sep 27, 2012 at 08:16:11PM +0530, Ramkumar Ramachandra wrote:

> diff --git a/Documentation/git-config.txt b/Documentation/git-config.txt
> index eaea079..c8db03f 100644
> --- a/Documentation/git-config.txt
> +++ b/Documentation/git-config.txt
> @@ -205,6 +205,9 @@ $GIT_DIR/config::
>  	User-specific configuration file. Also called "global"
>  	configuration file.
>  
> +$GIT_GLOBAL_CONFIG::
> +	Overrides the path of the global configuration file.
> +

Like the other reviews, I am not overly enthused. If we are going to add
a new variable, I think $GIT_HOME makes a lot more sense. But it really
sounds like using $XDG_CONFIG_HOME would be even simpler.

Also, have you considered using a config include? Like:

  $ echo '[include]path = ~/my-dotfiles/gitconfig' >~/.gitconfig

It's a one-time setup, and then you get updates inside my-dotfiles
forever. The one-time setup is annoying, but you have to bootstrap
somehow (e.g., you're going to have to copy a .profile or similar to get
the GIT_GLOBAL_CONFIG variable set).

-Peff

```

## Junio C Hamano, 2012-09-27 17:50

Subject: Re: [PATCH] config: introduce GIT_GLOBAL_CONFIG to override ~/.gitconfig
Message-ID: <7vk3vfqrrp.fsf@alter.siamese.dyndns.org>
URL: https://gitlist.dev/e/7vk3vfqrrp.fsf%40alter.siamese.dyndns.org
In-Reply-To: <vpq626zjtds.fsf@grenoble-inp.fr>

```
Matthieu Moy <Matthieu.Moy@grenoble-inp.fr> writes:

> Ramkumar Ramachandra <artagnon@gmail.com> writes:
>
>> diff --git a/Documentation/git-config.txt b/Documentation/git-config.txt
>> index eaea079..c8db03f 100644
>> --- a/Documentation/git-config.txt
>> +++ b/Documentation/git-config.txt
>> @@ -205,6 +205,9 @@ $GIT_DIR/config::
>>  	User-specific configuration file. Also called "global"
>>  	configuration file.
>>  
>> +$GIT_GLOBAL_CONFIG::
>> +	Overrides the path of the global configuration file.
>> +
>
> I'm not particularly in favor of introducing another environment
> variable, but if you are to introduce it, why just override the
> configuration file, and not $HOME completely (e.g. to override
> $HOME/.git-credentials too).
>
> There was a patch proposing that here ($GIT_HOME to override $HOME):

I think both of these are at the entrance of slippery slope to
insanity I'd rather not to venture into.

If somebody hates ~/.dotmanyfiles so much, why not do HOME=~/dots/,
instead of having to set GIT_HOME to move ~/.gitconfig, FROTZ_HOME
to move ~/.frotzconfig, MAIL_HOME to move ~/.mailrc, etc.?

I wouldn't be surprised if some _other_ things break with your HOME
pointing at a directory inside your home directory, but then it may
be better to fix that other thing instead.

```

## Junio C Hamano, 2012-09-27 19:57

Subject: Re: [PATCH] config: introduce GIT_GLOBAL_CONFIG to override ~/.gitconfig
Message-ID: <7vtxujp7c6.fsf@alter.siamese.dyndns.org>
URL: https://gitlist.dev/e/7vtxujp7c6.fsf%40alter.siamese.dyndns.org
In-Reply-To: <20120927173532.GD1547@sigill.intra.peff.net>

```
Jeff King <peff@peff.net> writes:

> Also, have you considered using a config include? Like:
>
>   $ echo '[include]path = ~/my-dotfiles/gitconfig' >~/.gitconfig

Very good suggestion.

> ... you have to bootstrap
> somehow (e.g., you're going to have to copy a .profile or similar to get
> the GIT_GLOBAL_CONFIG variable set).

Exactly my thought ;-)

```

## Matthieu Moy, 2012-09-27 20:51

Subject: Re: [PATCH] config: introduce GIT_GLOBAL_CONFIG to override ~/.gitconfig
Message-ID: <vpqzk4bfaua.fsf@grenoble-inp.fr>
URL: https://gitlist.dev/e/vpqzk4bfaua.fsf%40grenoble-inp.fr
In-Reply-To: <20120927173532.GD1547@sigill.intra.peff.net>

```
Jeff King <peff@peff.net> writes:

> Also, have you considered using a config include? Like:
>
>   $ echo '[include]path = ~/my-dotfiles/gitconfig' >~/.gitconfig
>
> It's a one-time setup, and then you get updates inside my-dotfiles
> forever. The one-time setup is annoying, but you have to bootstrap
> somehow (e.g., you're going to have to copy a .profile or similar to get
> the GIT_GLOBAL_CONFIG variable set).

I also strongly prefer symlinks or include over environment variables.
Relying on environment variables makes the setup a bit fragile, partly
because I often mess things up with my shell (e.g. I once had different
shell and environment variables in ~/.xsession and in actual shells,
hence different configuration depending on whether I launch stuff from
my window-manager or from a shell).

I could understand using environment variables for one-shot
configuration change (e.g. HOME=/tmp/ git whatever), but then $HOME is
sufficient in general.

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

```

## Ramkumar Ramachandra, 2012-09-28 07:05

Subject: Re: [PATCH] config: introduce GIT_GLOBAL_CONFIG to override ~/.gitconfig
Message-ID: <CALkWK0=CCLrfM2Jr_JNVP0VQnp1dvRAkDjRrTsogvpD8rGrumw@mail.gmail.com>
URL: https://gitlist.dev/e/CALkWK0%3DCCLrfM2Jr_JNVP0VQnp1dvRAkDjRrTsogvpD8rGrumw%40mail.gmail.com
In-Reply-To: <20120927173532.GD1547@sigill.intra.peff.net>

```
Jeff King wrote:
> Like the other reviews, I am not overly enthused. If we are going to add
> a new variable, I think $GIT_HOME makes a lot more sense. But it really
> sounds like using $XDG_CONFIG_HOME would be even simpler.
>
> Also, have you considered using a config include? Like:
>
>   $ echo '[include]path = ~/my-dotfiles/gitconfig' >~/.gitconfig

Sounds like this is the way to go.  Or I could pick up Junio's
suggestion to use a Makefile.  I'll discontinue working on the patch.

Thanks.

Ram

```
