git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] config: read system-wide defaults from /etc/gitconfig

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Feb 14, 2007, 11:48 UTC
Message-ID
<Pine.LNX.4.63.0702141246160.22628@wbgn013.biozentrum.uni-wuerzburg.de>
In-Reply-To
<slrnet5p5h.s9h.siprbaum@xp.machine.xx>

The settings in /etc/gitconfig can be overridden in ~/.gitconfig, which in turn can be overridden in .git/config.

Signed-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
---
	On Wed, 14 Feb 2007, Peter Baumann wrote:
	> Andy Parkins <andyparkins@gmail.com> schrieb:
	> >
	> > With the release of 1.5.0 I added legacyheaders=false and
	> > usedelatbaseoffset=true to my repositories.
	> >
	> > While doing that though, it felt wrong to be editing every 
	> > single config.  Is there a justification for having three 
	> > config files?
	> >
	> >  /etc/gitconfig
	> >  $HOME/.gitconfig
	> >  $GIT_DIR/config
	> >
	> > With /etc/gitconfig coming in at lowest priority?
	> 
	> I would like this, too. This would allow me to set e.g.
	> "diff.color = auto" for everyone one a machine. We use git there 
	> to only manage some config files and several simple perl 
	> scripts. As it is mostly myself who does the editing, 
	> ~/.gitconfig works for *ME*.
	> 
	> But I'd like to set this globally so that my colluagues which 
	> don't have much clue about git don't need to bother about config 
	> settings. And yes, editing every single repo doesn't seem like 
	> an elegant solution.
	Voilà.
 Documentation/config.txt |    3 ++-
 cache.h                  |    1 +
 config.c                 |    2 ++
 3 files changed, 5 insertions(+), 1 deletions(-)
diff --git a/Documentation/config.txt b/Documentation/config.txt
index 3865535..1dd90d8 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -5,7 +5,8 @@ The git configuration file contains a number of variables that affect
 the git command's behavior. `.git/config` file for each repository
 is used to store the information for that repository, and
 `$HOME/.gitconfig` is used to store per user information to give
-fallback values for `.git/config` file.
+fallback values for `.git/config` file. The file `/etc/gitconfig`
+can be used to store system-wide defaults.
 
 They can be used by both the git plumbing
 and the porcelains. The variables are divided into sections, where
diff --git a/cache.h b/cache.h
index 44941c0..e316f66 100644
--- a/cache.h
+++ b/cache.h
@@ -123,6 +123,7 @@ extern int cache_errno;
 #define INDEX_ENVIRONMENT "GIT_INDEX_FILE"
 #define GRAFT_ENVIRONMENT "GIT_GRAFT_FILE"
 #define TEMPLATE_DIR_ENVIRONMENT "GIT_TEMPLATE_DIR"
+#define ETC_GITCONFIG "/etc/gitconfig"
 #define CONFIG_ENVIRONMENT "GIT_CONFIG"
 #define CONFIG_LOCAL_ENVIRONMENT "GIT_CONFIG_LOCAL"
 #define EXEC_PATH_ENVIRONMENT "GIT_EXEC_PATH"
diff --git a/config.c b/config.c
index d821071..b0c0948 100644
--- a/config.c
+++ b/config.c
@@ -383,6 +383,8 @@ int git_config(config_fn_t fn)
 	 * config file otherwise. */
 	filename = getenv(CONFIG_ENVIRONMENT);
 	if (!filename) {
+		if (!access(ETC_GITCONFIG, R_OK))
+			ret += git_config_from_file(fn, ETC_GITCONFIG);
 		home = getenv("HOME");
 		filename = getenv(CONFIG_LOCAL_ENVIRONMENT);
 		if (!filename)
-- 
1.5.0.rc4.2447.g06287-dirty
Previous: Peter BaumannNext: Junio C Hamano
Message 3 of 30 in “/etc/gitconfig”
  1. Andy ParkinsFeb 14, 2007
  2. Peter BaumannFeb 14, 2007
  3. config: read system-wide defaults from /etc/gitconfigJohannes Schindelin, Feb 14, 2007
  4. Junio C HamanoFeb 14, 2007
  5. Johannes SchindelinFeb 14, 2007
  6. Junio C HamanoFeb 14, 2007
  7. Johannes SchindelinFeb 14, 2007
  8. Junio C HamanoFeb 14, 2007
  9. Nicolas PitreFeb 14, 2007
  10. Junio C HamanoFeb 14, 2007
  11. Andy ParkinsFeb 15, 2007
  12. Junio C HamanoFeb 15, 2007
  13. Han-Wen NienhuysFeb 14, 2007
  14. Junio C HamanoFeb 14, 2007
  15. Johannes SchindelinFeb 14, 2007
  16. Junio C HamanoFeb 14, 2007
  17. Johannes SchindelinFeb 14, 2007
  18. Johannes SchindelinFeb 14, 2007
  19. Junio C HamanoFeb 15, 2007
  20. Junio C HamanoFeb 15, 2007
  21. Eric WongFeb 15, 2007
  22. Eric WongFeb 15, 2007
  23. Junio C HamanoFeb 15, 2007
  24. Johannes SchindelinFeb 15, 2007
  25. Junio C HamanoFeb 15, 2007
  26. Johannes SchindelinFeb 15, 2007
  27. Jakub NarebskiFeb 19, 2007
  28. Uwe Kleine-KönigFeb 14, 2007
  29. Allow config files to be includedAlex Riesen, Feb 16, 2007
  30. Alex RiesenFeb 16, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.