~/.git/config ?

17 messages, 10 authors, 2016-06-15 · open the first message on its own page

~/.git/config ?

From: Anand Kumria <hidden>
Date: 2016-06-15 22:42:27

Hi,

git is unable to construct a reasonable default email address in my
current environment.  So, I use GIT_AUTHOR_EMAIL and GIT_COMMITTER_EMAIL
to override things.

This has worked well but, now, I need to vary the email address for some
repositories.  Unfortunately the environment variables override
.git/config.

It would be good if things were like:
	- try to construct one automagically
	- use ~/.git/config (if available)
	- use .git/config
	- use environment variables

That way I could set my default email address in ~/.git/config and
override it as required for those repositories that need it.

Thanks,
Anand

-- 
 `When any government, or any church for that matter, undertakes to say to
  its subjects, "This you may not read, this you must not see, this you are
  forbidden to know," the end result is tyranny and oppression no matter how
  holy the motives' -- Robert A Heinlein, "If this goes on --"

Re: ~/.git/config ?

From: Timo Hirvonen <hidden>
Date: 2016-06-15 22:42:27

Anand Kumria [off-list ref] wrote:
Hi,

git is unable to construct a reasonable default email address in my
current environment.  So, I use GIT_AUTHOR_EMAIL and GIT_COMMITTER_EMAIL
to override things.

This has worked well but, now, I need to vary the email address for some
repositories.  Unfortunately the environment variables override
.git/config.

It would be good if things were like:
	- try to construct one automagically
	- use ~/.git/config (if available)
	- use .git/config
	- use environment variables

That way I could set my default email address in ~/.git/config and
override it as required for those repositories that need it.
I backup my $HOME using git, so there's a .git directory in ~.  I don't
think a global config file is really needed but it would be nice if
.git/config would override the environment variables, not the other way
around.

-- 
http://onion.dynserv.net/~timo/

Re: ~/.git/config ?

From: Jakub Narebski <hidden>
Date: 2016-06-15 22:42:27

Timo Hirvonen wrote:
Anand Kumria [off-list ref] wrote:
quoted
Hi,

git is unable to construct a reasonable default email address in my
current environment.  So, I use GIT_AUTHOR_EMAIL and GIT_COMMITTER_EMAIL
to override things.

This has worked well but, now, I need to vary the email address for some
repositories.  Unfortunately the environment variables override
.git/config.

It would be good if things were like:
     - try to construct one automagically
     - use ~/.git/config (if available)
     - use .git/config
     - use environment variables

That way I could set my default email address in ~/.git/config and
override it as required for those repositories that need it.
I backup my $HOME using git, so there's a .git directory in ~.  I don't
think a global config file is really needed but it would be nice if
.git/config would override the environment variables, not the other way
around.
Well, I'm not sure if environmental variables overriding wouldn't make
invocations like 'GIT_DIR=something git command' possible.

There are templates, also for config. Currently git lacks user (not
repository) config file, e.g. ~/.gitconfig (common for all repositories).

-- 
Jakub Narebski
Warsaw, Poland

Re: ~/.git/config ?

From: Petr Baudis <hidden>
Date: 2016-06-15 22:42:27

Dear diary, on Fri, May 26, 2006 at 06:33:25PM CEST, I got a letter
where Timo Hirvonen [off-list ref] said that...
I backup my $HOME using git, so there's a .git directory in ~.
Then it should be called ~/.gitconfig. :-)
I don't think a global config file is really needed but it would be
nice if .git/config would override the environment variables, not the
other way around.
Then you have no other way to override .git/config e.g. when committing
patches submitted by other people.

-- 
				Petr "Pasky" Baudis
Stuff: http://pasky.or.cz/
A person is just about as big as the things that make them angry.

Re: ~/.git/config ?

From: Timo Hirvonen <hidden>
Date: 2016-06-15 22:42:27

Petr Baudis [off-list ref] wrote:
Dear diary, on Fri, May 26, 2006 at 06:33:25PM CEST, I got a letter
where Timo Hirvonen [off-list ref] said that...
quoted
I backup my $HOME using git, so there's a .git directory in ~.
Then it should be called ~/.gitconfig. :-)
I just wanted to point the fact that ~/.git/ could not be used :)
quoted
I don't think a global config file is really needed but it would be
nice if .git/config would override the environment variables, not the
other way around.
Then you have no other way to override .git/config e.g. when committing
patches submitted by other people.
git commit --author "name <email>"

-- 
http://onion.dynserv.net/~timo/

Re: ~/.git/config ?

From: Petr Baudis <hidden>
Date: 2016-06-15 22:42:27

Dear diary, on Fri, May 26, 2006 at 07:05:26PM CEST, I got a letter
where Timo Hirvonen [off-list ref] said that...
quoted
quoted
I don't think a global config file is really needed but it would be
nice if .git/config would override the environment variables, not the
other way around.
Then you have no other way to override .git/config e.g. when committing
patches submitted by other people.
git commit --author "name <email>"
Except that this just sets the environment variables for you. :-)

Now, you could do some really funny stuff with overriding the
environment variables at git commit's entry point with .git/config
stuff, then possibly setting them again in case --author was passed, but
I seriously think such a confusion is not worth it.

-- 
				Petr "Pasky" Baudis
Stuff: http://pasky.or.cz/
A person is just about as big as the things that make them angry.

Re: ~/.git/config ?

From: Junio C Hamano <hidden>
Date: 2016-06-15 22:42:27

Anand Kumria [off-list ref] writes:
It would be good if things were like:
	- try to construct one automagically
	- use ~/.git/config (if available)
	- use .git/config
	- use environment variables

That way I could set my default email address in ~/.git/config and
override it as required for those repositories that need it.
If you mean by the above "do all of these and take the last
value that was available", that sounds sane.  Except perhaps I
would suggest to use ~/.git-config instead.  Some people seem to
want to track their home directory with git, and that way, your
personal fallback default file can be version controlled.

Re: ~/.git/config ?

From: Pavel Roskin <hidden>
Date: 2016-06-15 22:42:27

On Fri, 2006-05-26 at 18:38 +0200, Petr Baudis wrote:
Dear diary, on Fri, May 26, 2006 at 06:33:25PM CEST, I got a letter
where Timo Hirvonen [off-list ref] said that...
quoted
I backup my $HOME using git, so there's a .git directory in ~.
Then it should be called ~/.gitconfig. :-)
No, make it .gitrc for compatibility with .cvsrc, .lynxrc and others.

I know, it's becoming a bikeshed issue :-)

-- 
Regards,
Pavel Roskin

Re: ~/.git/config ?

From: Petr Baudis <hidden>
Date: 2016-06-15 22:42:27

Dear diary, on Sat, May 27, 2006 at 04:36:22AM CEST, I got a letter
where Pavel Roskin [off-list ref] said that...
On Fri, 2006-05-26 at 18:38 +0200, Petr Baudis wrote:
quoted
Dear diary, on Fri, May 26, 2006 at 06:33:25PM CEST, I got a letter
where Timo Hirvonen [off-list ref] said that...
quoted
I backup my $HOME using git, so there's a .git directory in ~.
Then it should be called ~/.gitconfig. :-)
No, make it .gitrc for compatibility with .cvsrc, .lynxrc and others.
~/.gitrc might get useful for actually doing what ~/.cvsrc or ~/.cgrc
does, that is providing default options for git commands. ~/.gitconfig
would just give you per-user defaults for the repository config file.

-- 
				Petr "Pasky" Baudis
Stuff: http://pasky.or.cz/
A person is just about as big as the things that make them angry.

Re: ~/.git/config ?

From: Linus Torvalds <torvalds@osdl.org>
Date: 2016-06-15 22:42:27


On Sat, 27 May 2006, Petr Baudis wrote:
~/.gitrc might get useful for actually doing what ~/.cvsrc or ~/.cgrc
does, that is providing default options for git commands. ~/.gitconfig
would just give you per-user defaults for the repository config file.
I don't think the two are necessarily any different.

I do think that
 (a) we might as well use the same syntax. There's no point in having 
     different syntax for the files, even if they end up having slightly 
     different usage.
 (b) a "user-wide" config file would tend to have different things in it 
     than a per-repository one, but some of the things it would have in it 
     are the things that we currently put in the per-repository one. 
     Notably exactly the "user.name" and "user.email" values.
 (c) having a user- (and perhaps a system-) wide config file would make 
     some things that we do not _yet_ support in the .git/config file 
     format more natural, but that doesn't necessarily mean that having 
     them on a per-repo basis would be wrong either.

As an example of (c), let's say that somebody wants to use the CVS aliases 
with git. They've used cvs for years, and as a result their brain has 
atrophied, and they have a really hard time teaching their fingers to 
write "git commit" when they want to write "cvs ci".

So they would do "alias cvs git" in a desperate attempt to save themselves 
from CVS, and then add

	[alias "co"]
		cmd = commit -a

to their .gitrc file. Now, the only thing we'd need to do is to teach 
"git.c" to parse that simple "alias.$1.command" variable, and that really 
sounds pretty damn easy, no?

And that really does make more sense in a user-wide ".gitrc" file. But at 
the same time, there's really no reason to _disallow_ it from the 
repo-private .git/config file either. For example, you could do

	[alias "publish"]
		cmd = push public.site.com:/pub/scm/my-public-repo

and that is somethign that actually makes sense as a per-repository 
command alias, so that "git publish" does the right thing for just _that_ 
repository.

So I would argue that yes, ".gitrc" makes sense, and no, we shouldn't have 
a separate ".gitrc" and ".gitconfig", because I think what we really would 
want is a way to do default .git/config entries, and that it is _also_ a 
very natural way to add some things that we don't do yet.

			Linus

PS. I really like my [alias "cmd"] idea. _All_ my ideas are great, of 
course, but this one seems even better than some others. No?

Re: ~/.git/config ?

From: Linus Torvalds <torvalds@osdl.org>
Date: 2016-06-15 22:42:27


On Fri, 26 May 2006, Linus Torvalds wrote:
So they would do "alias cvs git" in a desperate attempt to save themselves 
from CVS, and then add

	[alias "co"]
		cmd = commit -a
That, of course, would be confusing.

It should be "ci" for commit, and "co" for "checkout".

Duh. Chalk it up to me not having used cvs in the last three or four years 
or so (we used it at transmeta, although I can hope that they've since 
seen the light ;).

			Linus

Re: ~/.git/config ?

From: Jakub Narebski <hidden>
Date: 2016-06-15 22:42:27

Linus Torvalds wrote:
PS. I really like my [alias "cmd"] idea. _All_ my ideas are great, of 
course, but this one seems even better than some others. No?
So, would we use it also for default options of commands, like

        [alias "log"]
                cmd = log -p -M -C

(we could implement "git whatchanges" as an alias, keeping it's man page, or
sharing it with "git log").

-- 
Jakub Narebski
Warsaw, Poland

Re: ~/.git/config ?

From: Nikolai Weibull <hidden>
Date: 2016-06-15 22:42:27

On 5/27/06, Pavel Roskin [off-list ref] wrote:
On Fri, 2006-05-26 at 18:38 +0200, Petr Baudis wrote:
quoted
Dear diary, on Fri, May 26, 2006 at 06:33:25PM CEST, I got a letter
where Timo Hirvonen [off-list ref] said that...
quoted
I backup my $HOME using git, so there's a .git directory in ~.
Then it should be called ~/.gitconfig. :-)
No, make it .gitrc for compatibility with .cvsrc, .lynxrc and others.

I know, it's becoming a bikeshed issue :-)
I want to paint part of it as well!

Wouldn't we be futureproofing ourselves by stuffing it in a
subdirectory instead?  What if we want to add more files later?

Also, can we please make sure to make the location of the file (or
directory) configurable through an environment variable, e.g.,
GIT_CONFIG, GIT_USER_CONFIG, GIT_HOME, or GIT_USER_HOME?

Peace.

  nikolai

Re: ~/.git/config ?

From: Timo Hirvonen <hidden>
Date: 2016-06-15 22:42:27

"Nikolai Weibull" [off-list ref] wrote:
On 5/27/06, Pavel Roskin [off-list ref] wrote:
quoted
On Fri, 2006-05-26 at 18:38 +0200, Petr Baudis wrote:
quoted
Then it should be called ~/.gitconfig. :-)
No, make it .gitrc for compatibility with .cvsrc, .lynxrc and others.

I know, it's becoming a bikeshed issue :-)
I want to paint part of it as well!

Wouldn't we be futureproofing ourselves by stuffing it in a
subdirectory instead?  What if we want to add more files later?
Makes sense, we may want to put templates to ~/.gitsomething/templates/.

-- 
http://onion.dynserv.net/~timo/

[PATCH] Read configuration also from ~/.gitrc

From: Petr Baudis <hidden>
Date: 2016-06-15 22:42:27

  Hi,

Dear diary, on Fri, May 26, 2006 at 05:28:37PM CEST, I got a letter
where Anand Kumria [off-list ref] said that...
git is unable to construct a reasonable default email address in my
current environment.  So, I use GIT_AUTHOR_EMAIL and GIT_COMMITTER_EMAIL
to override things.

This has worked well but, now, I need to vary the email address for some
repositories.  Unfortunately the environment variables override
.git/config.

It would be good if things were like:
	- try to construct one automagically
	- use ~/.git/config (if available)
	- use .git/config
	- use environment variables

That way I could set my default email address in ~/.git/config and
override it as required for those repositories that need it.
  hmm, might it be as simple as this?

---

This command makes Git read configuration from ~/.gitrc in addition
to the per-repository .git/config configuration file, and updates
the documentation accordingly (and also expands it a little).

Idea by Anand Kumria.

Signed-off-by: Petr Baudis <redacted>
---

 Documentation/git-commit-tree.txt |    9 +++++----
 Documentation/git-repo-config.txt |    6 +++---
 Documentation/git-var.txt         |    5 +++--
 Documentation/git.txt             |   15 +++++++++++----
 config.c                          |    6 +++++-
 5 files changed, 27 insertions(+), 14 deletions(-)
diff --git a/Documentation/git-commit-tree.txt b/Documentation/git-commit-tree.txt
index 41d1a1c..1b0d102 100644
--- a/Documentation/git-commit-tree.txt
+++ b/Documentation/git-commit-tree.txt
@@ -49,8 +49,9 @@ A commit encapsulates:
 - committer name and email and the commit time.
 
 If not provided, "git-commit-tree" uses your name, hostname and domain to
-provide author and committer info. This can be overridden by
-either `.git/config` file, or using the following environment variables.
+provide author and committer info. This can be overridden by either the
+`~/.gitrc` file, the `.git/config` file, or using the following
+environment variables.
 
 	GIT_AUTHOR_NAME
 	GIT_AUTHOR_EMAIL
@@ -60,8 +61,8 @@ either `.git/config` file, or using the 
 
 (nb "<", ">" and "\n"s are stripped)
 
-In `.git/config` file, the following items are used for GIT_AUTHOR_NAME and
-GIT_AUTHOR_EMAIL:
+In the configuration file, the following items are used for GIT_AUTHOR_NAME
+and GIT_AUTHOR_EMAIL:
 
 	[user]
 		name = "Your Name"
diff --git a/Documentation/git-repo-config.txt b/Documentation/git-repo-config.txt
index 660c18f..bb7f81f 100644
--- a/Documentation/git-repo-config.txt
+++ b/Documentation/git-repo-config.txt
@@ -3,7 +3,7 @@ git-repo-config(1)
 
 NAME
 ----
-git-repo-config - Get and set options in .git/config
+git-repo-config - Get and set git runtime configuration options
 
 
 SYNOPSIS
@@ -37,7 +37,7 @@ no checks or transformations are perform
 
 This command will fail if:
 
-. The .git/config file is invalid,
+. The configuration file is invalid,
 . Can not write to .git/config,
 . no section was provided,
 . the section or key is invalid,
@@ -70,7 +70,7 @@ OPTIONS
 	Remove all matching lines from .git/config.
 
 -l, --list::
-	List all variables set in .git/config.
+	List all variables set in ~/.gitrc or .git/config.
 
 
 EXAMPLE
diff --git a/Documentation/git-var.txt b/Documentation/git-var.txt
index a5b1a0d..4679aef 100644
--- a/Documentation/git-var.txt
+++ b/Documentation/git-var.txt
@@ -18,8 +18,9 @@ OPTIONS
 -------
 -l::
 	Cause the logical variables to be listed. In addition, all the
-	variables of the git configuration file .git/config are listed
-	as well. (However, the configuration variables listing functionality
+	variables of the git configuration files `~/.gitrc` and `.git/config`
+	are listed as well.
+	(However, the configuration variables listing functionality
 	is deprecated in favor of `git-repo-config -l`.)
 
 EXAMPLE
diff --git a/Documentation/git.txt b/Documentation/git.txt
index e474bdf..f4e5df5 100644
--- a/Documentation/git.txt
+++ b/Documentation/git.txt
@@ -116,7 +116,7 @@ gitlink:git-read-tree[1]::
 	Reads tree information into the index.
 
 gitlink:git-repo-config[1]::
-	Get and set options in .git/config.
+	Get and set git runtime configuration options.
 
 gitlink:git-unpack-objects[1]::
 	Unpacks objects out of a packed archive.
@@ -473,8 +473,7 @@ gitlink:gitk[1]::
 Configuration Mechanism
 -----------------------
 
-Starting from 0.99.9 (actually mid 0.99.8.GIT), `.git/config` file
-is used to hold per-repository configuration options.  It is a
+You can adjust the Git behaviour by a configuration file.  It is a
 simple text file modelled after `.ini` format familiar to some
 people.  Here is an example:
 
@@ -496,7 +495,15 @@ #
 ------------
 
 Various commands read from the configuration file and adjust
-their operation accordingly.
+their operation accordingly. See gitlink:git-repo-config[1]
+for details and list of options.
+
+Git first reads the per-user global configuration from `~/.gitrc`
+and then per-repository configuration from the `.git/config` file.
+Either of these files may be missing; the per-repository configuration
+wins in case of a conflict. Some behaviour can be also tweaked using
+environment variables; in general, they take precedence over configuration
+options.
 
 
 Identifier Terminology
diff --git a/config.c b/config.c
index 0248c6d..8a98865 100644
--- a/config.c
+++ b/config.c
@@ -312,7 +312,11 @@ int git_config_from_file(config_fn_t fn,
 
 int git_config(config_fn_t fn)
 {
-	return git_config_from_file(fn, git_path("config"));
+	int ret = 0;
+	if (getenv("HOME"))
+		ret += git_config_from_file(fn, mkpath("%s/.gitrc", getenv("HOME")));
+	ret += git_config_from_file(fn, git_path("config"));
+	return ret;
 }
 
 /*

-- 
				Petr "Pasky" Baudis
Stuff: http://pasky.or.cz/
A person is just about as big as the things that make them angry.

Re: [PATCH] Read configuration also from ~/.gitrc

From: Johannes Schindelin <hidden>
Date: 2016-06-15 22:42:27

Hi,

On Mon, 29 May 2006, Petr Baudis wrote:
quoted hunk
diff --git a/config.c b/config.c
index 0248c6d..8a98865 100644
--- a/config.c
+++ b/config.c
@@ -312,7 +312,11 @@ int git_config_from_file(config_fn_t fn,
 
 int git_config(config_fn_t fn)
 {
-	return git_config_from_file(fn, git_path("config"));
+	int ret = 0;
+	if (getenv("HOME"))
+		ret += git_config_from_file(fn, mkpath("%s/.gitrc", getenv("HOME")));
+	ret += git_config_from_file(fn, git_path("config"));
+	return ret;
 }
 
 /*

But would this not break for the normal case? If you override one key in 
the repository's config, with this patch, repo-config will barf. The 
normal case is that you do not expect multiple values for the same key. 
Your patch reads both ~/.gitrc and $GIT_DIR/config, and if a key has a 
value in both (even if they are identical), repo-config will error out.

Further, storing a key will no longer work. This is an obscure side 
effect of this patch not caring about storing anything in ~/.gitrc: If you 
find the key section (or the key) in ~/.gitrc, the offset will be stored, 
_and used on $GIT_DIR/config_!

I agree it is nice to have a global git configuration, but I have it: I 
use templates.

Ciao,
Dscho

Re: [PATCH] Read configuration also from ~/.gitrc

From: Jakub Narebski <hidden>
Date: 2016-06-15 22:42:27

Johannes Schindelin wrote:
But would this not break for the normal case? If you override one key in 
the repository's config, with this patch, repo-config will barf. The 
normal case is that you do not expect multiple values for the same key. 
Your patch reads both ~/.gitrc and $GIT_DIR/config, and if a key has a 
value in both (even if they are identical), repo-config will error out.
So the patch was to simplistic. Values from user's configuration file
~/.gitrc should be marked, to be overridden by $GIT_DIR/config per
repository configuration file.
 
Further, storing a key will no longer work. This is an obscure side 
effect of this patch not caring about storing anything in ~/.gitrc: If you 
find the key section (or the key) in ~/.gitrc, the offset will be stored, 
_and used on $GIT_DIR/config_!
I think that storing a key should (unless new option --user-config or
--global is used) should store it in $GIT_DIR/config file; of course index
has to be found there, and if not found it key should be created. Per
configuration file offsets?
I agree it is nice to have a global git configuration, but I have it: I 
use templates.
There are system-wide templates. git-init-db(1) doesn't show default
directory for _user_ templates...


And I guess that these are the issues why Junio C Hamano wrote:
* The 'pu' branch, in addition, has these.

 - $HOME/.gitrc (Petr Baudis)
      Read configuration also from ~/.gitrc

   * I like this but it breaks the tests big time.  Not "next"
     material yet, unfortunately.
 

-- 
Jakub Narebski
Warsaw, Poland
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help