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

Document ability to disable template directory in git-init

From
BKBoris Kolpackov <boris@codesynthesis.com>
Date
Jul 3, 2025, 14:40 UTC
Message-ID
<boris.20250703161436@codesynthesis.com>
Hello,

Looking at the git-init(1) man page, there doesn't appear to be a way to disable copying the contents of the default template directory, other than passing a path pointing to an empty directory.

However, if one passes an empty path, for example with the --template option, then git does not complain and does not copy anything:

git init --template=

Looking at the code, this undocumented (AFAICS) behavior appears to be there at least from git 2.1:

static void copy_templates(const char *template_dir)
{
	...
	if (!template_dir)
		template_dir = getenv(TEMPLATE_DIR_ENVIRONMENT);
	if (!template_dir)
		template_dir = init_db_template_dir;
	if (!template_dir)
		template_dir = system_path(DEFAULT_GIT_TEMPLATE_DIR);
	if (!template_dir[0])
		return;
For reference, the corresponding code in 2.50:
static void copy_templates(const char *option_template)
{
	const char *template_dir = get_template_dir(option_template);
	
	...
	if (!template_dir || !*template_dir)
		return;

I would like to suggest that we document this behavior so that it can be relied upon. The motivation for omitting the default template are repositories created by tools, such as package managers, for the sole purpose of fetching some information from remotes. In this case all the stuff copied from the template (such as hooks) is an unnecessary waste of time and space.

Looking at the git-init(1) man page, the TEMPLATE DIRECTORY section seems like the natural place to document this semantics. For example, we could add the following sentence after the list of all the places where the template directory can be specified:

"If the specified template directory is an empty path (for example, --template=), then no template will be copied."

Let me know what you think.

Thanks, Boris

Next: Han Young
Message 1 of 7 in “Document ability to disable template directory in git-init”
  1. Boris KolpackovJul 3, 2025
  2. Han YoungJul 4, 2025
  3. Boris KolpackovJul 4, 2025
  4. Todd ZullingerJul 4, 2025
  5. Jeff KingJul 6, 2025
  6. Kristoffer HaugsbakkJul 4, 2025
  7. Kristoffer HaugsbakkJul 4, 2025

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.