Git development
 help / color / mirror / Atom feed
* [PATCH] dir: use per-worktree repository ignore patterns upon request
@ 2026-04-24 17:09 D. Ben Knoble
  2026-04-24 19:35 ` brian m. carlson
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: D. Ben Knoble @ 2026-04-24 17:09 UTC (permalink / raw)
  To: git
  Cc: D. Ben Knoble, brian m . carlson, Patrick Steinhardt, Taylor Blau,
	Caleb White, Calvin Wan, Junio C Hamano, Elijah Newren,
	Andrew Berry, Jeff King, Derrick Stolee

Today we have $GIT_DIR/info/exclude for the main worktree, but $(git
rev-parse --git-dir)/info/exclude for secondary worktrees does not
actually contribute to ignore specs; instead, secondary worktrees also
use $GIT_COMMON_DIR/info/exclude.

Some users may prefer each worktree use its own ignore file; some may
prefer both; some may prefer the current behavior.

Add, test, and document extensions.worktreeIgnore that controls which
set of ignore files to use for worktrees.

Signed-off-by: D. Ben Knoble <ben.knoble+github@gmail.com>
---

Notes (benknoble/commits):
    Discussed briefly at https://lore.kernel.org/git/CALnO6CCXmA+ATT7CuyWkU6P8qmLCCpMi5Ppr1c78s0heznpVyw@mail.gmail.com/T

    This is based on next (4f69b47b94 (Merge branch 'ps/test-set-e-clean' into
    next, 2026-04-23)) but cleanly applies to master (94f057755b (Git 2.54,
    2026-04-19)) and seen (50541634cb (Merge branch
    'js/parseopt-subcommand-autocorrection' into seen, 2026-04-23)).

 Documentation/config/extensions.adoc |  7 ++++
 Documentation/git-worktree.adoc      |  3 ++
 Documentation/gitignore.adoc         |  6 ++--
 dir.c                                | 48 +++++++++++++++++++++++---
 t/meson.build                        |  1 +
 t/t2408-worktree-ignore.sh           | 50 ++++++++++++++++++++++++++++
 6 files changed, 109 insertions(+), 6 deletions(-)
 create mode 100755 t/t2408-worktree-ignore.sh

diff --git a/Documentation/config/extensions.adoc b/Documentation/config/extensions.adoc
index be6678bb5b..5bfb06a54b 100644
--- a/Documentation/config/extensions.adoc
+++ b/Documentation/config/extensions.adoc
@@ -148,3 +148,10 @@ details.
 +
 For historical reasons, this extension is respected regardless of the
 `core.repositoryFormatVersion` setting.
+
+worktreeIgnore:::
+	If enabled, then worktrees will load per-repository ignore files from
+	`$GIT_DIR/info/exclude` (that is,
+	`$GIT_COMMON_DIR/worktrees/<id>/info/exclude`). If set to `merge`, then
+	both `$GIT_COMMON_DIR/info/exclude` and `$GIT_DIR/info/exclude` are
+	used.
diff --git a/Documentation/git-worktree.adoc b/Documentation/git-worktree.adoc
index fbf8426cd9..611c1e06b0 100644
--- a/Documentation/git-worktree.adoc
+++ b/Documentation/git-worktree.adoc
@@ -412,6 +412,9 @@ linkgit:gitrepository-layout[5] for details.
 When `extensions.worktreeConfig` is enabled, the config file
 `.git/worktrees/<id>/config.worktree` is read after `.git/config` is.
 
+See `extensions.worktreeIgnore` in linkgit:git-config[1] to control how
+per-repository ignore files are found in worktrees.
+
 LIST OUTPUT FORMAT
 ------------------
 The `worktree list` command has two output formats. The default format shows the
diff --git a/Documentation/gitignore.adoc b/Documentation/gitignore.adoc
index a3d24e5c34..d6976a44e4 100644
--- a/Documentation/gitignore.adoc
+++ b/Documentation/gitignore.adoc
@@ -7,7 +7,7 @@ gitignore - Specifies intentionally untracked files to ignore
 
 SYNOPSIS
 --------
-$XDG_CONFIG_HOME/git/ignore, $GIT_DIR/info/exclude, .gitignore
+$XDG_CONFIG_HOME/git/ignore, $GIT_COMMON_DIR/info/exclude, .gitignore
 
 DESCRIPTION
 -----------
@@ -34,7 +34,9 @@ precedence, the last matching pattern decides the outcome):
    includes such `.gitignore` files in its repository, containing patterns for
    files generated as part of the project build.
 
- * Patterns read from `$GIT_DIR/info/exclude`.
+ * Patterns read from `$GIT_COMMON_DIR/info/exclude`. (See
+   `extensions.worktreeIgnore` in linkgit:git-config[1] to change how this
+   applies to worktrees.)
 
  * Patterns read from the file specified by the configuration
    variable `core.excludesFile`.
diff --git a/dir.c b/dir.c
index fcb8f6dd2a..9592eb0062 100644
--- a/dir.c
+++ b/dir.c
@@ -36,6 +36,7 @@
 #include "trace2.h"
 #include "tree.h"
 #include "hex.h"
+#include "worktree.h"
 
  /*
   * The maximum size of a pattern/exclude file. If the file exceeds this size
@@ -3478,6 +3479,23 @@ int remove_dir_recursively(struct strbuf *path, int flag)
 }
 
 static GIT_PATH_FUNC(git_path_info_exclude, "info/exclude")
+static const char *git_worktree_info_exclude(void)
+{
+	static const char *ret;
+	if (!ret)
+	{
+		const struct worktree *wt = get_worktree_from_repository(the_repository);
+		ret = worktree_git_path(wt, "info/exclude");
+	}
+	return ret;
+}
+
+static void standard_exclude_from_info(const char *path, struct dir_struct *dir)
+{
+	struct oid_stat *oid_stat = dir->untracked ? &dir->internal.ss_info_exclude : NULL;
+	if (!access_or_warn(path, R_OK, 0))
+		add_patterns_from_file_1(dir, path, oid_stat);
+}
 
 void setup_standard_excludes(struct dir_struct *dir)
 {
@@ -3492,10 +3510,32 @@ void setup_standard_excludes(struct dir_struct *dir)
 
 	/* per repository user preference */
 	if (startup_info->have_repository) {
-		const char *path = git_path_info_exclude();
-		if (!access_or_warn(path, R_OK, 0))
-			add_patterns_from_file_1(dir, path,
-						 dir->untracked ? &dir->internal.ss_info_exclude : NULL);
+		/* extensions.worktreeIgnore determines which includes we add */
+		const char *wt_ignore;
+		int do_wt_ignore;
+		if (repo_config_get_value(the_repository,
+					  "extensions.worktreeIgnore",
+					  &wt_ignore)) {
+			/* unset: use main/.git/info/exclude */
+			standard_exclude_from_info(git_path_info_exclude(), dir);
+			return;
+		}
+		do_wt_ignore = git_parse_maybe_bool(wt_ignore);
+		if (!do_wt_ignore) {
+			/* false: as above */
+			standard_exclude_from_info(git_path_info_exclude(), dir);
+		} else if (do_wt_ignore > 0 || !strcmp(wt_ignore, "worktree")) {
+			/* true/worktree: use worktree/.git‡/info/exclude
+			 * ‡: resolving .git */
+			standard_exclude_from_info(git_worktree_info_exclude(), dir);
+		} else if (!strcmp(wt_ignore, "merge")) {
+			/* merge both! worktree last */
+			standard_exclude_from_info(git_path_info_exclude(), dir);
+			standard_exclude_from_info(git_worktree_info_exclude(), dir);
+		} else {
+			die(_("invalid value for '%s': '%s'"),
+			      "extensions.worktreeIgnore", wt_ignore);
+		}
 	}
 }
 
diff --git a/t/meson.build b/t/meson.build
index 7528e5cda5..30624b59e8 100644
--- a/t/meson.build
+++ b/t/meson.build
@@ -307,6 +307,7 @@ integration_tests = [
   't2405-worktree-submodule.sh',
   't2406-worktree-repair.sh',
   't2407-worktree-heads.sh',
+  't2408-worktree-ignore.sh',
   't2500-untracked-overwriting.sh',
   't2501-cwd-empty.sh',
   't3000-ls-files-others.sh',
diff --git a/t/t2408-worktree-ignore.sh b/t/t2408-worktree-ignore.sh
new file mode 100755
index 0000000000..67644ddd8d
--- /dev/null
+++ b/t/t2408-worktree-ignore.sh
@@ -0,0 +1,50 @@
+#!/bin/sh
+
+test_description='extensions.worktreeIgnore'
+
+. ./test-lib.sh
+
+test_expect_success 'setup' '
+	test_commit init &&
+	git worktree add wt &&
+	echo main >.git/info/exclude &&
+	echo contents >main &&
+	echo contents >wt/main &&
+	wt_exclude="$(git -C wt rev-parse --git-dir)"/info/exclude &&
+	mkdir -p "$(dirname "$wt_exclude")" &&
+	echo worktree >"$wt_exclude" &&
+	echo contents >worktree &&
+	echo contents >wt/worktree
+'
+
+test_ignore_main() {
+	git check-ignore main &&
+	git -C wt check-ignore main
+}
+
+test_expect_success 'ignores main items by default' '
+	test_ignore_main
+'
+
+test_expect_success 'ignores main items with extensions.worktreeIgnore=no' '
+	test_config extensions.worktreeIgnore no &&
+	test_ignore_main
+'
+
+test_expect_success 'ignores worktree items with extensions.worktreeIgnore=worktree' '
+	test_config extensions.worktreeIgnore worktree &&
+	git check-ignore main &&
+	! git check-ignore worktree &&
+	! git -C wt check-ignore main &&
+	git -C wt check-ignore worktree
+'
+
+test_expect_success 'ignores all items with extensions.worktreeIgnore=merge' '
+	test_config extensions.worktreeIgnore merge &&
+	git check-ignore main &&
+	! git check-ignore worktree &&
+	git -C wt check-ignore main &&
+	git -C wt check-ignore worktree
+'
+
+test_done

base-commit: 4f69b47b940100b02630f745a52f9d9850f122b2
-- 
2.54.0.rc2.544.gc7ae2d5bb8.dirty


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH] dir: use per-worktree repository ignore patterns upon request
  2026-04-24 17:09 [PATCH] dir: use per-worktree repository ignore patterns upon request D. Ben Knoble
@ 2026-04-24 19:35 ` brian m. carlson
  2026-04-24 19:53 ` Phillip Wood
  2026-05-08 14:14 ` [PATCH v2] ignore: note info/exclude lives in GIT_COMMON_DIR, not GIT_DIR D. Ben Knoble
  2 siblings, 0 replies; 10+ messages in thread
From: brian m. carlson @ 2026-04-24 19:35 UTC (permalink / raw)
  To: D. Ben Knoble
  Cc: git, Patrick Steinhardt, Taylor Blau, Caleb White, Calvin Wan,
	Junio C Hamano, Elijah Newren, Andrew Berry, Jeff King,
	Derrick Stolee

[-- Attachment #1: Type: text/plain, Size: 1040 bytes --]

On 2026-04-24 at 17:09:19, D. Ben Knoble wrote:
> Today we have $GIT_DIR/info/exclude for the main worktree, but $(git
> rev-parse --git-dir)/info/exclude for secondary worktrees does not
> actually contribute to ignore specs; instead, secondary worktrees also
> use $GIT_COMMON_DIR/info/exclude.
> 
> Some users may prefer each worktree use its own ignore file; some may
> prefer both; some may prefer the current behavior.
> 
> Add, test, and document extensions.worktreeIgnore that controls which
> set of ignore files to use for worktrees.

I was wondering if we could make something like
`extensions.worktreeInfoFiles` or something and also make the
`info/attributes` (and maybe `info/sparse-checkout`) file used instead.
I think that would be somewhat better than having additional options
added on after the fact and be a little more generally applicable.

What do you think?  My apologies for not mentioning this sooner before
you'd already sent a patch.
-- 
brian m. carlson (they/them)
Toronto, Ontario, CA

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 325 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] dir: use per-worktree repository ignore patterns upon request
  2026-04-24 17:09 [PATCH] dir: use per-worktree repository ignore patterns upon request D. Ben Knoble
  2026-04-24 19:35 ` brian m. carlson
@ 2026-04-24 19:53 ` Phillip Wood
  2026-04-25  3:06   ` Junio C Hamano
  2026-05-08 14:14 ` [PATCH v2] ignore: note info/exclude lives in GIT_COMMON_DIR, not GIT_DIR D. Ben Knoble
  2 siblings, 1 reply; 10+ messages in thread
From: Phillip Wood @ 2026-04-24 19:53 UTC (permalink / raw)
  To: D. Ben Knoble, git
  Cc: brian m . carlson, Patrick Steinhardt, Taylor Blau, Caleb White,
	Calvin Wan, Junio C Hamano, Elijah Newren, Andrew Berry,
	Jeff King, Derrick Stolee

Hi Ben

On 24/04/2026 18:09, D. Ben Knoble wrote:
> Today we have $GIT_DIR/info/exclude for the main worktree, but $(git
> rev-parse --git-dir)/info/exclude for secondary worktrees does not
> actually contribute to ignore specs; instead, secondary worktrees also
> use $GIT_COMMON_DIR/info/exclude.

Sharing the same set of exclude patterns between all worktrees seems 
like a reasonable thing to do - it would be a pain to have to populate 
them every time a new worktree was created.

	git rev-parse --git-path info/exclude

always returns the correct path because it uses repo_git_path() which 
knows whether a particular path is per-worktree or resides under 
$GIT_COMMON_DIR. It is best to avoid constructing paths manually using 
"git rev-parse --git-dir"

> Some users may prefer each worktree use its own ignore file; some may
> prefer both; some may prefer the current behavior.

This sounds quite hypothetical - do we have a concrete use case for 
per-worktree exclude files?

If there is a use for per-worktree excludes it would be much better to 
use a different path such as "info.worktree/exclude" so that the main 
worktree can have both shared and per-worktree excludes. We could use 
"exclude.worktree" like "config.worktree" but then we'd be in danger of 
adding new ".worktree" files in the future if we want to add 
per-worktree versions of other files that live under "info/"

Thanks

Phillip

> Add, test, and document extensions.worktreeIgnore that controls which
> set of ignore files to use for worktrees.
> 
> Signed-off-by: D. Ben Knoble <ben.knoble+github@gmail.com>
> ---
> 
> Notes (benknoble/commits):
>      Discussed briefly at https://lore.kernel.org/git/CALnO6CCXmA+ATT7CuyWkU6P8qmLCCpMi5Ppr1c78s0heznpVyw@mail.gmail.com/T
> 
>      This is based on next (4f69b47b94 (Merge branch 'ps/test-set-e-clean' into
>      next, 2026-04-23)) but cleanly applies to master (94f057755b (Git 2.54,
>      2026-04-19)) and seen (50541634cb (Merge branch
>      'js/parseopt-subcommand-autocorrection' into seen, 2026-04-23)).
> 
>   Documentation/config/extensions.adoc |  7 ++++
>   Documentation/git-worktree.adoc      |  3 ++
>   Documentation/gitignore.adoc         |  6 ++--
>   dir.c                                | 48 +++++++++++++++++++++++---
>   t/meson.build                        |  1 +
>   t/t2408-worktree-ignore.sh           | 50 ++++++++++++++++++++++++++++
>   6 files changed, 109 insertions(+), 6 deletions(-)
>   create mode 100755 t/t2408-worktree-ignore.sh
> 
> diff --git a/Documentation/config/extensions.adoc b/Documentation/config/extensions.adoc
> index be6678bb5b..5bfb06a54b 100644
> --- a/Documentation/config/extensions.adoc
> +++ b/Documentation/config/extensions.adoc
> @@ -148,3 +148,10 @@ details.
>   +
>   For historical reasons, this extension is respected regardless of the
>   `core.repositoryFormatVersion` setting.
> +
> +worktreeIgnore:::
> +	If enabled, then worktrees will load per-repository ignore files from
> +	`$GIT_DIR/info/exclude` (that is,
> +	`$GIT_COMMON_DIR/worktrees/<id>/info/exclude`). If set to `merge`, then
> +	both `$GIT_COMMON_DIR/info/exclude` and `$GIT_DIR/info/exclude` are
> +	used.
> diff --git a/Documentation/git-worktree.adoc b/Documentation/git-worktree.adoc
> index fbf8426cd9..611c1e06b0 100644
> --- a/Documentation/git-worktree.adoc
> +++ b/Documentation/git-worktree.adoc
> @@ -412,6 +412,9 @@ linkgit:gitrepository-layout[5] for details.
>   When `extensions.worktreeConfig` is enabled, the config file
>   `.git/worktrees/<id>/config.worktree` is read after `.git/config` is.
>   
> +See `extensions.worktreeIgnore` in linkgit:git-config[1] to control how
> +per-repository ignore files are found in worktrees.
> +
>   LIST OUTPUT FORMAT
>   ------------------
>   The `worktree list` command has two output formats. The default format shows the
> diff --git a/Documentation/gitignore.adoc b/Documentation/gitignore.adoc
> index a3d24e5c34..d6976a44e4 100644
> --- a/Documentation/gitignore.adoc
> +++ b/Documentation/gitignore.adoc
> @@ -7,7 +7,7 @@ gitignore - Specifies intentionally untracked files to ignore
>   
>   SYNOPSIS
>   --------
> -$XDG_CONFIG_HOME/git/ignore, $GIT_DIR/info/exclude, .gitignore
> +$XDG_CONFIG_HOME/git/ignore, $GIT_COMMON_DIR/info/exclude, .gitignore
>   
>   DESCRIPTION
>   -----------
> @@ -34,7 +34,9 @@ precedence, the last matching pattern decides the outcome):
>      includes such `.gitignore` files in its repository, containing patterns for
>      files generated as part of the project build.
>   
> - * Patterns read from `$GIT_DIR/info/exclude`.
> + * Patterns read from `$GIT_COMMON_DIR/info/exclude`. (See
> +   `extensions.worktreeIgnore` in linkgit:git-config[1] to change how this
> +   applies to worktrees.)
>   
>    * Patterns read from the file specified by the configuration
>      variable `core.excludesFile`.
> diff --git a/dir.c b/dir.c
> index fcb8f6dd2a..9592eb0062 100644
> --- a/dir.c
> +++ b/dir.c
> @@ -36,6 +36,7 @@
>   #include "trace2.h"
>   #include "tree.h"
>   #include "hex.h"
> +#include "worktree.h"
>   
>    /*
>     * The maximum size of a pattern/exclude file. If the file exceeds this size
> @@ -3478,6 +3479,23 @@ int remove_dir_recursively(struct strbuf *path, int flag)
>   }
>   
>   static GIT_PATH_FUNC(git_path_info_exclude, "info/exclude")
> +static const char *git_worktree_info_exclude(void)
> +{
> +	static const char *ret;
> +	if (!ret)
> +	{
> +		const struct worktree *wt = get_worktree_from_repository(the_repository);
> +		ret = worktree_git_path(wt, "info/exclude");
> +	}
> +	return ret;
> +}
> +
> +static void standard_exclude_from_info(const char *path, struct dir_struct *dir)
> +{
> +	struct oid_stat *oid_stat = dir->untracked ? &dir->internal.ss_info_exclude : NULL;
> +	if (!access_or_warn(path, R_OK, 0))
> +		add_patterns_from_file_1(dir, path, oid_stat);
> +}
>   
>   void setup_standard_excludes(struct dir_struct *dir)
>   {
> @@ -3492,10 +3510,32 @@ void setup_standard_excludes(struct dir_struct *dir)
>   
>   	/* per repository user preference */
>   	if (startup_info->have_repository) {
> -		const char *path = git_path_info_exclude();
> -		if (!access_or_warn(path, R_OK, 0))
> -			add_patterns_from_file_1(dir, path,
> -						 dir->untracked ? &dir->internal.ss_info_exclude : NULL);
> +		/* extensions.worktreeIgnore determines which includes we add */
> +		const char *wt_ignore;
> +		int do_wt_ignore;
> +		if (repo_config_get_value(the_repository,
> +					  "extensions.worktreeIgnore",
> +					  &wt_ignore)) {
> +			/* unset: use main/.git/info/exclude */
> +			standard_exclude_from_info(git_path_info_exclude(), dir);
> +			return;
> +		}
> +		do_wt_ignore = git_parse_maybe_bool(wt_ignore);
> +		if (!do_wt_ignore) {
> +			/* false: as above */
> +			standard_exclude_from_info(git_path_info_exclude(), dir);
> +		} else if (do_wt_ignore > 0 || !strcmp(wt_ignore, "worktree")) {
> +			/* true/worktree: use worktree/.git‡/info/exclude
> +			 * ‡: resolving .git */
> +			standard_exclude_from_info(git_worktree_info_exclude(), dir);
> +		} else if (!strcmp(wt_ignore, "merge")) {
> +			/* merge both! worktree last */
> +			standard_exclude_from_info(git_path_info_exclude(), dir);
> +			standard_exclude_from_info(git_worktree_info_exclude(), dir);
> +		} else {
> +			die(_("invalid value for '%s': '%s'"),
> +			      "extensions.worktreeIgnore", wt_ignore);
> +		}
>   	}
>   }
>   
> diff --git a/t/meson.build b/t/meson.build
> index 7528e5cda5..30624b59e8 100644
> --- a/t/meson.build
> +++ b/t/meson.build
> @@ -307,6 +307,7 @@ integration_tests = [
>     't2405-worktree-submodule.sh',
>     't2406-worktree-repair.sh',
>     't2407-worktree-heads.sh',
> +  't2408-worktree-ignore.sh',
>     't2500-untracked-overwriting.sh',
>     't2501-cwd-empty.sh',
>     't3000-ls-files-others.sh',
> diff --git a/t/t2408-worktree-ignore.sh b/t/t2408-worktree-ignore.sh
> new file mode 100755
> index 0000000000..67644ddd8d
> --- /dev/null
> +++ b/t/t2408-worktree-ignore.sh
> @@ -0,0 +1,50 @@
> +#!/bin/sh
> +
> +test_description='extensions.worktreeIgnore'
> +
> +. ./test-lib.sh
> +
> +test_expect_success 'setup' '
> +	test_commit init &&
> +	git worktree add wt &&
> +	echo main >.git/info/exclude &&
> +	echo contents >main &&
> +	echo contents >wt/main &&
> +	wt_exclude="$(git -C wt rev-parse --git-dir)"/info/exclude &&
> +	mkdir -p "$(dirname "$wt_exclude")" &&
> +	echo worktree >"$wt_exclude" &&
> +	echo contents >worktree &&
> +	echo contents >wt/worktree
> +'
> +
> +test_ignore_main() {
> +	git check-ignore main &&
> +	git -C wt check-ignore main
> +}
> +
> +test_expect_success 'ignores main items by default' '
> +	test_ignore_main
> +'
> +
> +test_expect_success 'ignores main items with extensions.worktreeIgnore=no' '
> +	test_config extensions.worktreeIgnore no &&
> +	test_ignore_main
> +'
> +
> +test_expect_success 'ignores worktree items with extensions.worktreeIgnore=worktree' '
> +	test_config extensions.worktreeIgnore worktree &&
> +	git check-ignore main &&
> +	! git check-ignore worktree &&
> +	! git -C wt check-ignore main &&
> +	git -C wt check-ignore worktree
> +'
> +
> +test_expect_success 'ignores all items with extensions.worktreeIgnore=merge' '
> +	test_config extensions.worktreeIgnore merge &&
> +	git check-ignore main &&
> +	! git check-ignore worktree &&
> +	git -C wt check-ignore main &&
> +	git -C wt check-ignore worktree
> +'
> +
> +test_done
> 
> base-commit: 4f69b47b940100b02630f745a52f9d9850f122b2


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] dir: use per-worktree repository ignore patterns upon request
  2026-04-24 19:53 ` Phillip Wood
@ 2026-04-25  3:06   ` Junio C Hamano
  0 siblings, 0 replies; 10+ messages in thread
From: Junio C Hamano @ 2026-04-25  3:06 UTC (permalink / raw)
  To: Phillip Wood
  Cc: D. Ben Knoble, git, brian m . carlson, Patrick Steinhardt,
	Taylor Blau, Caleb White, Calvin Wan, Elijah Newren, Andrew Berry,
	Jeff King, Derrick Stolee

Phillip Wood <phillip.wood123@gmail.com> writes:

> Sharing the same set of exclude patterns between all worktrees seems 
> like a reasonable thing to do - it would be a pain to have to populate 
> them every time a new worktree was created.
>
> 	git rev-parse --git-path info/exclude
>
> always returns the correct path because it uses repo_git_path() which 
> knows whether a particular path is per-worktree or resides under 
> $GIT_COMMON_DIR. It is best to avoid constructing paths manually using 
> "git rev-parse --git-dir"

Great to see the best practice raised, like this.

>> Some users may prefer each worktree use its own ignore file; some may
>> prefer both; some may prefer the current behavior.
>
> This sounds quite hypothetical - do we have a concrete use case for 
> per-worktree exclude files?

I can see if somebody wants to have different subset of paths
checked out by setting up separate sparse settings.  But marking
what paths are never be part of the project (which is what exclude
is about)?  I do not think it is useful in general.

The only case I can think of is a repository that houses more than
one completely unrelated histories, perhaps being cheapster on a
hosting site that charges per number of repositories or something
silly like that.

My https://git.kernel.org/pub/scm/git/git.git/ repository houses two
completely unrelated histories, one the project data, and 'todo'
that are mostly about tools I personally use to maintain the
project.  Ideally, the latter branch should have been created and
maintained as a separate repository, but back them I didn't have
write access outside pub/scm/git/git.git/ (notably pub/scm/git/
itself was not writable to me) and that was the only reason why that
unrelated history is pushed into the same repository as a separate
and unrelated 'todo' branch.  It is not a recommended practice, and
if this configuration is primarily to cater to such layout, I do not
think we want to add it.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH v2] ignore: note info/exclude lives in GIT_COMMON_DIR, not GIT_DIR
  2026-04-24 17:09 [PATCH] dir: use per-worktree repository ignore patterns upon request D. Ben Knoble
  2026-04-24 19:35 ` brian m. carlson
  2026-04-24 19:53 ` Phillip Wood
@ 2026-05-08 14:14 ` D. Ben Knoble
  2026-05-09 14:08   ` brian m. carlson
                     ` (2 more replies)
  2 siblings, 3 replies; 10+ messages in thread
From: D. Ben Knoble @ 2026-05-08 14:14 UTC (permalink / raw)
  To: git
  Cc: D. Ben Knoble, brian m . carlson, Patrick Steinhardt, Taylor Blau,
	Caleb White, Calvin Wan, Junio C Hamano, Elijah Newren,
	Andrew Berry, Jeff King, Derrick Stolee, Phillip Wood

gitignore(5) says that the per-repository ignore file is
$GIT_DIR/info/exclude, but in a worktree that is not the case:

    git rev-parse --git-path info/exclude
    /path/to/main/worktree/.git/info/exclude
    git rev-parse --git-common-dir
    /path/to/main/worktree/.git

We actually use $GIT_COMMON_DIR/info/exclude. Adjust the documentation
to say so.

Signed-off-by: D. Ben Knoble <ben.knoble+github@gmail.com>
---

Notes (benknoble/commits):
    Changes in v2:
    
    Only adjust the documentation.
    
    brian points out that a more general extension would allow using more
    info/ files as "per-worktree," which I don't have the impetus to
    implement myself.
    
    Phillip and Junio asked for a concrete use case:
    
        A colleague is developing a tool for managing the "skill files" of
        various LLM tools (Claude, Windsurf, etc.). The files have
        requirements that make it hard to generically ignore them (e.g.,
        filenames and front-matter have to match), but different tasks
        (corresponding to worktrees) may want different active skills, so it
        is desirable to ignore the files. Think of this like node_modules.
    
        Unfortunately, since per-worktree ignores don't work, the current
        solution is to put a .gitignore file in the corresponding directory
        with the installed skills that ignores itself and the installed
        skills.
    
    Since overall reactions seem fairly negative (or require a more general
    extension, which I think is probably the right course but not simply
    implemented), I've opted to adjust the docs. They originally confused
    me, as I was surprised when my colleague reported that per-worktree
    ignores didn't work (the docs imply they should by use of $GIT_DIR).
    
    Link to v1: <e3ee0a11b566dd2cc605447c111ae4620bce0fe6.1777050300.git.ben.knoble+github@gmail.com>
    
    v1 notes:
    
    Discussed briefly at https://lore.kernel.org/git/CALnO6CCXmA+ATT7CuyWkU6P8qmLCCpMi5Ppr1c78s0heznpVyw@mail.gmail.com/T
    
    This is based on next (4f69b47b94 (Merge branch 'ps/test-set-e-clean'
    into next, 2026-04-23)) but cleanly applies to master (94f057755b (Git
    2.54, 2026-04-19)) and seen (50541634cb (Merge branch
    'js/parseopt-subcommand-autocorrection' into seen, 2026-04-23)).

 Documentation/gitignore.adoc | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/Documentation/gitignore.adoc b/Documentation/gitignore.adoc
index a3d24e5c34..c423b650de 100644
--- a/Documentation/gitignore.adoc
+++ b/Documentation/gitignore.adoc
@@ -7,7 +7,7 @@ gitignore - Specifies intentionally untracked files to ignore
 
 SYNOPSIS
 --------
-$XDG_CONFIG_HOME/git/ignore, $GIT_DIR/info/exclude, .gitignore
+$XDG_CONFIG_HOME/git/ignore, $GIT_COMMON_DIR/info/exclude, .gitignore
 
 DESCRIPTION
 -----------
@@ -34,7 +34,7 @@ precedence, the last matching pattern decides the outcome):
    includes such `.gitignore` files in its repository, containing patterns for
    files generated as part of the project build.
 
- * Patterns read from `$GIT_DIR/info/exclude`.
+ * Patterns read from `$GIT_COMMON_DIR/info/exclude`.
 
  * Patterns read from the file specified by the configuration
    variable `core.excludesFile`.

base-commit: 4f69b47b940100b02630f745a52f9d9850f122b2
-- 
2.54.0.564.ge3ee0a11b5.dirty


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH v2] ignore: note info/exclude lives in GIT_COMMON_DIR, not GIT_DIR
  2026-05-08 14:14 ` [PATCH v2] ignore: note info/exclude lives in GIT_COMMON_DIR, not GIT_DIR D. Ben Knoble
@ 2026-05-09 14:08   ` brian m. carlson
  2026-05-11 10:30   ` Phillip Wood
  2026-05-12 21:21   ` [PATCH v3] " D. Ben Knoble
  2 siblings, 0 replies; 10+ messages in thread
From: brian m. carlson @ 2026-05-09 14:08 UTC (permalink / raw)
  To: D. Ben Knoble
  Cc: git, Patrick Steinhardt, Taylor Blau, Caleb White, Calvin Wan,
	Junio C Hamano, Elijah Newren, Andrew Berry, Jeff King,
	Derrick Stolee, Phillip Wood

[-- Attachment #1: Type: text/plain, Size: 611 bytes --]

On 2026-05-08 at 14:14:14, D. Ben Knoble wrote:
> gitignore(5) says that the per-repository ignore file is
> $GIT_DIR/info/exclude, but in a worktree that is not the case:
> 
>     git rev-parse --git-path info/exclude
>     /path/to/main/worktree/.git/info/exclude
>     git rev-parse --git-common-dir
>     /path/to/main/worktree/.git
> 
> We actually use $GIT_COMMON_DIR/info/exclude. Adjust the documentation
> to say so.

This seems quite reasonable.  I always appreciate documentation patches
that clarify things or fix inaccuracies.
-- 
brian m. carlson (they/them)
Toronto, Ontario, CA

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 325 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v2] ignore: note info/exclude lives in GIT_COMMON_DIR, not GIT_DIR
  2026-05-08 14:14 ` [PATCH v2] ignore: note info/exclude lives in GIT_COMMON_DIR, not GIT_DIR D. Ben Knoble
  2026-05-09 14:08   ` brian m. carlson
@ 2026-05-11 10:30   ` Phillip Wood
  2026-05-11 19:55     ` D. Ben Knoble
  2026-05-12 21:21   ` [PATCH v3] " D. Ben Knoble
  2 siblings, 1 reply; 10+ messages in thread
From: Phillip Wood @ 2026-05-11 10:30 UTC (permalink / raw)
  To: D. Ben Knoble, git
  Cc: brian m . carlson, Patrick Steinhardt, Taylor Blau, Caleb White,
	Calvin Wan, Junio C Hamano, Elijah Newren, Andrew Berry,
	Jeff King, Derrick Stolee, Phillip Wood

On 08/05/2026 15:14, D. Ben Knoble wrote:
> gitignore(5) says that the per-repository ignore file is
> $GIT_DIR/info/exclude, but in a worktree that is not the case:
> 
>      git rev-parse --git-path info/exclude
>      /path/to/main/worktree/.git/info/exclude
>      git rev-parse --git-common-dir
>      /path/to/main/worktree/.git
> 
> We actually use $GIT_COMMON_DIR/info/exclude. Adjust the documentation
> to say so.

Thanks for making the documentation match reality. Are there some more
instances than need to be changed? If I run

     git grep -n GIT_DIR/info origin/master Documentation/gitignore.adoc

I see

origin/master:Documentation/gitignore.adoc:10:$XDG_CONFIG_HOME/git/ignore, $GIT_DIR/info/exclude, .gitignore
origin/master:Documentation/gitignore.adoc:37: * Patterns read from `$GIT_DIR/info/exclude`.
origin/master:Documentation/gitignore.adoc:53:   the `$GIT_DIR/info/exclude` file.
origin/master:Documentation/gitignore.adoc:100:   such as $GIT_DIR/info/exclude and core.excludesFile, are treated as if
origin/master:Documentation/gitignore.adoc:149:`$GIT_DIR/info/exclude`. Patterns in the exclude file are used in addition to
origin/master:Documentation/gitignore.adoc:150:those in `$GIT_DIR/info/exclude`.

We also have a ton of other files under Documentation that mention
$GIT_DIR/info/... all of which, apart from the release notes, I
think should probably be using $GIT_COMMON_DIR but we can always do
that separately

Thanks

Phillip

> Signed-off-by: D. Ben Knoble <ben.knoble+github@gmail.com>
> ---
> 
> Notes (benknoble/commits):
>      Changes in v2:
>      
>      Only adjust the documentation.
>      
>      brian points out that a more general extension would allow using more
>      info/ files as "per-worktree," which I don't have the impetus to
>      implement myself.
>      
>      Phillip and Junio asked for a concrete use case:
>      
>          A colleague is developing a tool for managing the "skill files" of
>          various LLM tools (Claude, Windsurf, etc.). The files have
>          requirements that make it hard to generically ignore them (e.g.,
>          filenames and front-matter have to match), but different tasks
>          (corresponding to worktrees) may want different active skills, so it
>          is desirable to ignore the files. Think of this like node_modules.
>      
>          Unfortunately, since per-worktree ignores don't work, the current
>          solution is to put a .gitignore file in the corresponding directory
>          with the installed skills that ignores itself and the installed
>          skills.
>      
>      Since overall reactions seem fairly negative (or require a more general
>      extension, which I think is probably the right course but not simply
>      implemented), I've opted to adjust the docs. They originally confused
>      me, as I was surprised when my colleague reported that per-worktree
>      ignores didn't work (the docs imply they should by use of $GIT_DIR).
>      
>      Link to v1: <e3ee0a11b566dd2cc605447c111ae4620bce0fe6.1777050300.git.ben.knoble+github@gmail.com>
>      
>      v1 notes:
>      
>      Discussed briefly at https://lore.kernel.org/git/CALnO6CCXmA+ATT7CuyWkU6P8qmLCCpMi5Ppr1c78s0heznpVyw@mail.gmail.com/T
>      
>      This is based on next (4f69b47b94 (Merge branch 'ps/test-set-e-clean'
>      into next, 2026-04-23)) but cleanly applies to master (94f057755b (Git
>      2.54, 2026-04-19)) and seen (50541634cb (Merge branch
>      'js/parseopt-subcommand-autocorrection' into seen, 2026-04-23)).
> 
>   Documentation/gitignore.adoc | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/Documentation/gitignore.adoc b/Documentation/gitignore.adoc
> index a3d24e5c34..c423b650de 100644
> --- a/Documentation/gitignore.adoc
> +++ b/Documentation/gitignore.adoc
> @@ -7,7 +7,7 @@ gitignore - Specifies intentionally untracked files to ignore
>   
>   SYNOPSIS
>   --------
> -$XDG_CONFIG_HOME/git/ignore, $GIT_DIR/info/exclude, .gitignore
> +$XDG_CONFIG_HOME/git/ignore, $GIT_COMMON_DIR/info/exclude, .gitignore
>   
>   DESCRIPTION
>   -----------
> @@ -34,7 +34,7 @@ precedence, the last matching pattern decides the outcome):
>      includes such `.gitignore` files in its repository, containing patterns for
>      files generated as part of the project build.
>   
> - * Patterns read from `$GIT_DIR/info/exclude`.
> + * Patterns read from `$GIT_COMMON_DIR/info/exclude`.
>   
>    * Patterns read from the file specified by the configuration
>      variable `core.excludesFile`.
> 
> base-commit: 4f69b47b940100b02630f745a52f9d9850f122b2


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v2] ignore: note info/exclude lives in GIT_COMMON_DIR, not GIT_DIR
  2026-05-11 10:30   ` Phillip Wood
@ 2026-05-11 19:55     ` D. Ben Knoble
  0 siblings, 0 replies; 10+ messages in thread
From: D. Ben Knoble @ 2026-05-11 19:55 UTC (permalink / raw)
  To: phillip.wood
  Cc: git, brian m . carlson, Patrick Steinhardt, Taylor Blau,
	Caleb White, Calvin Wan, Junio C Hamano, Elijah Newren,
	Andrew Berry, Jeff King, Derrick Stolee

On Mon, May 11, 2026 at 6:30 AM Phillip Wood <phillip.wood123@gmail.com> wrote:
>
> On 08/05/2026 15:14, D. Ben Knoble wrote:
> > gitignore(5) says that the per-repository ignore file is
> > $GIT_DIR/info/exclude, but in a worktree that is not the case:
> >
> >      git rev-parse --git-path info/exclude
> >      /path/to/main/worktree/.git/info/exclude
> >      git rev-parse --git-common-dir
> >      /path/to/main/worktree/.git
> >
> > We actually use $GIT_COMMON_DIR/info/exclude. Adjust the documentation
> > to say so.
>
> Thanks for making the documentation match reality. Are there some more
> instances than need to be changed? If I run
>
>      git grep -n GIT_DIR/info origin/master Documentation/gitignore.adoc
>
> I see
>
> origin/master:Documentation/gitignore.adoc:10:$XDG_CONFIG_HOME/git/ignore, $GIT_DIR/info/exclude, .gitignore
> origin/master:Documentation/gitignore.adoc:37: * Patterns read from `$GIT_DIR/info/exclude`.
> origin/master:Documentation/gitignore.adoc:53:   the `$GIT_DIR/info/exclude` file.
> origin/master:Documentation/gitignore.adoc:100:   such as $GIT_DIR/info/exclude and core.excludesFile, are treated as if
> origin/master:Documentation/gitignore.adoc:149:`$GIT_DIR/info/exclude`. Patterns in the exclude file are used in addition to
> origin/master:Documentation/gitignore.adoc:150:those in `$GIT_DIR/info/exclude`.
>
> We also have a ton of other files under Documentation that mention
> $GIT_DIR/info/... all of which, apart from the release notes, I
> think should probably be using $GIT_COMMON_DIR but we can always do
> that separately
>
> Thanks
>
> Phillip

Good catch, thanks. Let me adjust the ignore-related ones and leave
the rest for now.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH v3] ignore: note info/exclude lives in GIT_COMMON_DIR, not GIT_DIR
  2026-05-08 14:14 ` [PATCH v2] ignore: note info/exclude lives in GIT_COMMON_DIR, not GIT_DIR D. Ben Knoble
  2026-05-09 14:08   ` brian m. carlson
  2026-05-11 10:30   ` Phillip Wood
@ 2026-05-12 21:21   ` D. Ben Knoble
  2026-05-13 14:02     ` Phillip Wood
  2 siblings, 1 reply; 10+ messages in thread
From: D. Ben Knoble @ 2026-05-12 21:21 UTC (permalink / raw)
  To: git
  Cc: D. Ben Knoble, brian m . carlson, Patrick Steinhardt, Taylor Blau,
	Caleb White, Junio C Hamano, Elijah Newren, Andrew Berry,
	Jeff King, Derrick Stolee, Phillip Wood, Shreyansh Paliwal,
	Dan Drake, Alex Galvin

gitignore(5) says that the per-repository ignore file is
$GIT_DIR/info/exclude, but in a worktree that is not the case:

    git rev-parse --git-path info/exclude
    /path/to/main/worktree/.git/info/exclude
    git rev-parse --git-common-dir
    /path/to/main/worktree/.git

We actually use $GIT_COMMON_DIR/info/exclude. Adjust the documentation
and some code comments to say so.

Signed-off-by: D. Ben Knoble <ben.knoble+github@gmail.com>
---

Notes (benknoble/commits):
    Changes in v3:
    
    Adjust more occurrences
    
    Link to v2: <d58b6e921d3005c6170fc6c47f175214acb3fa68.1778249267.git.ben.knoble+github@gmail.com>
    
    Changes in v2:
    
    Only adjust the documentation.
    
    brian points out that a more general extension would allow using more
    info/ files as "per-worktree," which I don't have the impetus to
    implement myself.
    
    Phillip and Junio asked for a concrete use case:
    
        A colleague is developing a tool for managing the "skill files" of
        various LLM tools (Claude, Windsurf, etc.). The files have
        requirements that make it hard to generically ignore them (e.g.,
        filenames and front-matter have to match), but different tasks
        (corresponding to worktrees) may want different active skills, so it
        is desirable to ignore the files. Think of this like node_modules.
    
        Unfortunately, since per-worktree ignores don't work, the current
        solution is to put a .gitignore file in the corresponding directory
        with the installed skills that ignores itself and the installed
        skills.
    
    Since overall reactions seem fairly negative (or require a more general
    extension, which I think is probably the right course but not simply
    implemented), I've opted to adjust the docs. They originally confused
    me, as I was surprised when my colleague reported that per-worktree
    ignores didn't work (the docs imply they should by use of $GIT_DIR).
    
    Link to v1: <e3ee0a11b566dd2cc605447c111ae4620bce0fe6.1777050300.git.ben.knoble+github@gmail.com>
    
    v1 notes:
    
    Discussed briefly at https://lore.kernel.org/git/CALnO6CCXmA+ATT7CuyWkU6P8qmLCCpMi5Ppr1c78s0heznpVyw@mail.gmail.com/T
    
    This is based on next (4f69b47b94 (Merge branch 'ps/test-set-e-clean'
    into next, 2026-04-23)) but cleanly applies to master (94f057755b (Git
    2.54, 2026-04-19)) and seen (50541634cb (Merge branch
    'js/parseopt-subcommand-autocorrection' into seen, 2026-04-23)).

 Documentation/git-ls-files.adoc    |  2 +-
 Documentation/git-svn.adoc         |  2 +-
 Documentation/gitformat-index.adoc |  4 ++--
 Documentation/gitignore.adoc       | 12 ++++++------
 dir.c                              |  4 ++--
 dir.h                              |  2 +-
 6 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/Documentation/git-ls-files.adoc b/Documentation/git-ls-files.adoc
index 58c529afbe..2b175388e1 100644
--- a/Documentation/git-ls-files.adoc
+++ b/Documentation/git-ls-files.adoc
@@ -331,7 +331,7 @@ can give `--exclude-per-directory=.gitignore`, and then specify:
   1. The file specified by the `core.excludesfile` configuration
      variable, if exists, or the `$XDG_CONFIG_HOME/git/ignore` file.
 
-  2. The `$GIT_DIR/info/exclude` file.
+  2. The `$GIT_COMMON_DIR/info/exclude` file.
 
 via the `--exclude-from=` option.
 
diff --git a/Documentation/git-svn.adoc b/Documentation/git-svn.adoc
index c26c12bab3..2a7fa60465 100644
--- a/Documentation/git-svn.adoc
+++ b/Documentation/git-svn.adoc
@@ -439,7 +439,7 @@ Any other arguments are passed directly to 'git log'
 'show-ignore'::
 	Recursively finds and lists the svn:ignore and svn:global-ignores
 	properties on directories. The output is suitable for appending to
-	the $GIT_DIR/info/exclude file.
+	the $GIT_COMMON_DIR/info/exclude file.
 
 'mkdirs'::
 	Attempts to recreate empty directories that core Git cannot track
diff --git a/Documentation/gitformat-index.adoc b/Documentation/gitformat-index.adoc
index 145cace1fe..f6a427cb49 100644
--- a/Documentation/gitformat-index.adoc
+++ b/Documentation/gitformat-index.adoc
@@ -291,14 +291,14 @@ Git index format
     sequence in variable width encoding. Each string describes the
     environment where the cache can be used.
 
-  - Stat data of $GIT_DIR/info/exclude. See "Index entry" section from
+  - Stat data of $GIT_COMMON_DIR/info/exclude. See "Index entry" section from
     ctime field until "file size".
 
   - Stat data of core.excludesFile
 
   - 32-bit dir_flags (see struct dir_struct)
 
-  - Hash of $GIT_DIR/info/exclude. A null hash means the file
+  - Hash of $GIT_COMMON_DIR/info/exclude. A null hash means the file
     does not exist.
 
   - Hash of core.excludesFile. A null hash means the file does
diff --git a/Documentation/gitignore.adoc b/Documentation/gitignore.adoc
index a3d24e5c34..7979e50f18 100644
--- a/Documentation/gitignore.adoc
+++ b/Documentation/gitignore.adoc
@@ -7,7 +7,7 @@ gitignore - Specifies intentionally untracked files to ignore
 
 SYNOPSIS
 --------
-$XDG_CONFIG_HOME/git/ignore, $GIT_DIR/info/exclude, .gitignore
+$XDG_CONFIG_HOME/git/ignore, $GIT_COMMON_DIR/info/exclude, .gitignore
 
 DESCRIPTION
 -----------
@@ -34,7 +34,7 @@ precedence, the last matching pattern decides the outcome):
    includes such `.gitignore` files in its repository, containing patterns for
    files generated as part of the project build.
 
- * Patterns read from `$GIT_DIR/info/exclude`.
+ * Patterns read from `$GIT_COMMON_DIR/info/exclude`.
 
  * Patterns read from the file specified by the configuration
    variable `core.excludesFile`.
@@ -50,7 +50,7 @@ be used.
    specific to a particular repository but which do not need to be shared
    with other related repositories (e.g., auxiliary files that live inside
    the repository but are specific to one user's workflow) should go into
-   the `$GIT_DIR/info/exclude` file.
+   the `$GIT_COMMON_DIR/info/exclude` file.
 
  * Patterns which a user wants Git to
    ignore in all situations (e.g., backup or temporary files generated by
@@ -97,7 +97,7 @@ PATTERN FORMAT
    match at any level below the `.gitignore` level.
 
  - Patterns read from exclude sources that are outside the working tree,
-   such as $GIT_DIR/info/exclude and core.excludesFile, are treated as if
+   such as $GIT_COMMON_DIR/info/exclude and core.excludesFile, are treated as if
    they are specified at the root of the working tree, i.e. a leading "/"
    in such patterns anchors the match at the root of the repository.
 
@@ -146,8 +146,8 @@ CONFIGURATION
 
 The optional configuration variable `core.excludesFile` indicates a path to a
 file containing patterns of file names to exclude, similar to
-`$GIT_DIR/info/exclude`.  Patterns in the exclude file are used in addition to
-those in `$GIT_DIR/info/exclude`.
+`$GIT_COMMON_DIR/info/exclude`. Patterns in the exclude file are used in
+addition to those in `$GIT_COMMON_DIR/info/exclude`.
 
 NOTES
 -----
diff --git a/dir.c b/dir.c
index fcb8f6dd2a..33c81c256e 100644
--- a/dir.c
+++ b/dir.c
@@ -2985,7 +2985,7 @@ static struct untracked_cache_dir *validate_untracked_cache(struct dir_struct *d
 		return NULL;
 
 	/*
-	 * We only support $GIT_DIR/info/exclude and core.excludesfile
+	 * We only support $GIT_COMMON_DIR/info/exclude and core.excludesfile
 	 * as the global ignore rule files. Any other additions
 	 * (e.g. from command line) invalidate the cache. This
 	 * condition also catches running setup_standard_excludes()
@@ -3078,7 +3078,7 @@ static struct untracked_cache_dir *validate_untracked_cache(struct dir_struct *d
 		istate->cache_changed |= UNTRACKED_CHANGED;
 	}
 
-	/* Validate $GIT_DIR/info/exclude and core.excludesfile */
+	/* Validate $GIT_COMMON_DIR/info/exclude and core.excludesfile */
 	root = dir->untracked->root;
 	if (!oideq(&dir->internal.ss_info_exclude.oid,
 		   &dir->untracked->ss_info_exclude.oid)) {
diff --git a/dir.h b/dir.h
index 20d4a078d6..83e0f648a8 100644
--- a/dir.h
+++ b/dir.h
@@ -153,7 +153,7 @@ struct oid_stat {
  *   - The list of files and directories of the directory in question
  *   - The $GIT_DIR/index
  *   - dir_struct flags
- *   - The content of $GIT_DIR/info/exclude
+ *   - The content of $GIT_COMMON_DIR/info/exclude
  *   - The content of core.excludesfile
  *   - The content (or the lack) of .gitignore of all parent directories
  *     from $GIT_WORK_TREE

base-commit: 59709faab07346122d819453f4ad6f3ccdaf618e
-- 
2.54.0.564.ge3ee0a11b5.dirty


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH v3] ignore: note info/exclude lives in GIT_COMMON_DIR, not GIT_DIR
  2026-05-12 21:21   ` [PATCH v3] " D. Ben Knoble
@ 2026-05-13 14:02     ` Phillip Wood
  0 siblings, 0 replies; 10+ messages in thread
From: Phillip Wood @ 2026-05-13 14:02 UTC (permalink / raw)
  To: D. Ben Knoble, git
  Cc: brian m . carlson, Patrick Steinhardt, Taylor Blau, Caleb White,
	Junio C Hamano, Elijah Newren, Andrew Berry, Jeff King,
	Derrick Stolee, Phillip Wood, Shreyansh Paliwal, Dan Drake,
	Alex Galvin

Hi Ben

On 12/05/2026 22:21, D. Ben Knoble wrote:
> gitignore(5) says that the per-repository ignore file is
> $GIT_DIR/info/exclude, but in a worktree that is not the case:
> 
>      git rev-parse --git-path info/exclude
>      /path/to/main/worktree/.git/info/exclude
>      git rev-parse --git-common-dir
>      /path/to/main/worktree/.git
> 
> We actually use $GIT_COMMON_DIR/info/exclude. Adjust the documentation
> and some code comments to say so.

Thanks for the re-roll, this looks good to me

Phillip

> Signed-off-by: D. Ben Knoble <ben.knoble+github@gmail.com>
> ---
> 
> Notes (benknoble/commits):
>      Changes in v3:
>      
>      Adjust more occurrences
>      
>      Link to v2: <d58b6e921d3005c6170fc6c47f175214acb3fa68.1778249267.git.ben.knoble+github@gmail.com>
>      
>      Changes in v2:
>      
>      Only adjust the documentation.
>      
>      brian points out that a more general extension would allow using more
>      info/ files as "per-worktree," which I don't have the impetus to
>      implement myself.
>      
>      Phillip and Junio asked for a concrete use case:
>      
>          A colleague is developing a tool for managing the "skill files" of
>          various LLM tools (Claude, Windsurf, etc.). The files have
>          requirements that make it hard to generically ignore them (e.g.,
>          filenames and front-matter have to match), but different tasks
>          (corresponding to worktrees) may want different active skills, so it
>          is desirable to ignore the files. Think of this like node_modules.
>      
>          Unfortunately, since per-worktree ignores don't work, the current
>          solution is to put a .gitignore file in the corresponding directory
>          with the installed skills that ignores itself and the installed
>          skills.
>      
>      Since overall reactions seem fairly negative (or require a more general
>      extension, which I think is probably the right course but not simply
>      implemented), I've opted to adjust the docs. They originally confused
>      me, as I was surprised when my colleague reported that per-worktree
>      ignores didn't work (the docs imply they should by use of $GIT_DIR).
>      
>      Link to v1: <e3ee0a11b566dd2cc605447c111ae4620bce0fe6.1777050300.git.ben.knoble+github@gmail.com>
>      
>      v1 notes:
>      
>      Discussed briefly at https://lore.kernel.org/git/CALnO6CCXmA+ATT7CuyWkU6P8qmLCCpMi5Ppr1c78s0heznpVyw@mail.gmail.com/T
>      
>      This is based on next (4f69b47b94 (Merge branch 'ps/test-set-e-clean'
>      into next, 2026-04-23)) but cleanly applies to master (94f057755b (Git
>      2.54, 2026-04-19)) and seen (50541634cb (Merge branch
>      'js/parseopt-subcommand-autocorrection' into seen, 2026-04-23)).
> 
>   Documentation/git-ls-files.adoc    |  2 +-
>   Documentation/git-svn.adoc         |  2 +-
>   Documentation/gitformat-index.adoc |  4 ++--
>   Documentation/gitignore.adoc       | 12 ++++++------
>   dir.c                              |  4 ++--
>   dir.h                              |  2 +-
>   6 files changed, 13 insertions(+), 13 deletions(-)
> 
> diff --git a/Documentation/git-ls-files.adoc b/Documentation/git-ls-files.adoc
> index 58c529afbe..2b175388e1 100644
> --- a/Documentation/git-ls-files.adoc
> +++ b/Documentation/git-ls-files.adoc
> @@ -331,7 +331,7 @@ can give `--exclude-per-directory=.gitignore`, and then specify:
>     1. The file specified by the `core.excludesfile` configuration
>        variable, if exists, or the `$XDG_CONFIG_HOME/git/ignore` file.
>   
> -  2. The `$GIT_DIR/info/exclude` file.
> +  2. The `$GIT_COMMON_DIR/info/exclude` file.
>   
>   via the `--exclude-from=` option.
>   
> diff --git a/Documentation/git-svn.adoc b/Documentation/git-svn.adoc
> index c26c12bab3..2a7fa60465 100644
> --- a/Documentation/git-svn.adoc
> +++ b/Documentation/git-svn.adoc
> @@ -439,7 +439,7 @@ Any other arguments are passed directly to 'git log'
>   'show-ignore'::
>   	Recursively finds and lists the svn:ignore and svn:global-ignores
>   	properties on directories. The output is suitable for appending to
> -	the $GIT_DIR/info/exclude file.
> +	the $GIT_COMMON_DIR/info/exclude file.
>   
>   'mkdirs'::
>   	Attempts to recreate empty directories that core Git cannot track
> diff --git a/Documentation/gitformat-index.adoc b/Documentation/gitformat-index.adoc
> index 145cace1fe..f6a427cb49 100644
> --- a/Documentation/gitformat-index.adoc
> +++ b/Documentation/gitformat-index.adoc
> @@ -291,14 +291,14 @@ Git index format
>       sequence in variable width encoding. Each string describes the
>       environment where the cache can be used.
>   
> -  - Stat data of $GIT_DIR/info/exclude. See "Index entry" section from
> +  - Stat data of $GIT_COMMON_DIR/info/exclude. See "Index entry" section from
>       ctime field until "file size".
>   
>     - Stat data of core.excludesFile
>   
>     - 32-bit dir_flags (see struct dir_struct)
>   
> -  - Hash of $GIT_DIR/info/exclude. A null hash means the file
> +  - Hash of $GIT_COMMON_DIR/info/exclude. A null hash means the file
>       does not exist.
>   
>     - Hash of core.excludesFile. A null hash means the file does
> diff --git a/Documentation/gitignore.adoc b/Documentation/gitignore.adoc
> index a3d24e5c34..7979e50f18 100644
> --- a/Documentation/gitignore.adoc
> +++ b/Documentation/gitignore.adoc
> @@ -7,7 +7,7 @@ gitignore - Specifies intentionally untracked files to ignore
>   
>   SYNOPSIS
>   --------
> -$XDG_CONFIG_HOME/git/ignore, $GIT_DIR/info/exclude, .gitignore
> +$XDG_CONFIG_HOME/git/ignore, $GIT_COMMON_DIR/info/exclude, .gitignore
>   
>   DESCRIPTION
>   -----------
> @@ -34,7 +34,7 @@ precedence, the last matching pattern decides the outcome):
>      includes such `.gitignore` files in its repository, containing patterns for
>      files generated as part of the project build.
>   
> - * Patterns read from `$GIT_DIR/info/exclude`.
> + * Patterns read from `$GIT_COMMON_DIR/info/exclude`.
>   
>    * Patterns read from the file specified by the configuration
>      variable `core.excludesFile`.
> @@ -50,7 +50,7 @@ be used.
>      specific to a particular repository but which do not need to be shared
>      with other related repositories (e.g., auxiliary files that live inside
>      the repository but are specific to one user's workflow) should go into
> -   the `$GIT_DIR/info/exclude` file.
> +   the `$GIT_COMMON_DIR/info/exclude` file.
>   
>    * Patterns which a user wants Git to
>      ignore in all situations (e.g., backup or temporary files generated by
> @@ -97,7 +97,7 @@ PATTERN FORMAT
>      match at any level below the `.gitignore` level.
>   
>    - Patterns read from exclude sources that are outside the working tree,
> -   such as $GIT_DIR/info/exclude and core.excludesFile, are treated as if
> +   such as $GIT_COMMON_DIR/info/exclude and core.excludesFile, are treated as if
>      they are specified at the root of the working tree, i.e. a leading "/"
>      in such patterns anchors the match at the root of the repository.
>   
> @@ -146,8 +146,8 @@ CONFIGURATION
>   
>   The optional configuration variable `core.excludesFile` indicates a path to a
>   file containing patterns of file names to exclude, similar to
> -`$GIT_DIR/info/exclude`.  Patterns in the exclude file are used in addition to
> -those in `$GIT_DIR/info/exclude`.
> +`$GIT_COMMON_DIR/info/exclude`. Patterns in the exclude file are used in
> +addition to those in `$GIT_COMMON_DIR/info/exclude`.
>   
>   NOTES
>   -----
> diff --git a/dir.c b/dir.c
> index fcb8f6dd2a..33c81c256e 100644
> --- a/dir.c
> +++ b/dir.c
> @@ -2985,7 +2985,7 @@ static struct untracked_cache_dir *validate_untracked_cache(struct dir_struct *d
>   		return NULL;
>   
>   	/*
> -	 * We only support $GIT_DIR/info/exclude and core.excludesfile
> +	 * We only support $GIT_COMMON_DIR/info/exclude and core.excludesfile
>   	 * as the global ignore rule files. Any other additions
>   	 * (e.g. from command line) invalidate the cache. This
>   	 * condition also catches running setup_standard_excludes()
> @@ -3078,7 +3078,7 @@ static struct untracked_cache_dir *validate_untracked_cache(struct dir_struct *d
>   		istate->cache_changed |= UNTRACKED_CHANGED;
>   	}
>   
> -	/* Validate $GIT_DIR/info/exclude and core.excludesfile */
> +	/* Validate $GIT_COMMON_DIR/info/exclude and core.excludesfile */
>   	root = dir->untracked->root;
>   	if (!oideq(&dir->internal.ss_info_exclude.oid,
>   		   &dir->untracked->ss_info_exclude.oid)) {
> diff --git a/dir.h b/dir.h
> index 20d4a078d6..83e0f648a8 100644
> --- a/dir.h
> +++ b/dir.h
> @@ -153,7 +153,7 @@ struct oid_stat {
>    *   - The list of files and directories of the directory in question
>    *   - The $GIT_DIR/index
>    *   - dir_struct flags
> - *   - The content of $GIT_DIR/info/exclude
> + *   - The content of $GIT_COMMON_DIR/info/exclude
>    *   - The content of core.excludesfile
>    *   - The content (or the lack) of .gitignore of all parent directories
>    *     from $GIT_WORK_TREE
> 
> base-commit: 59709faab07346122d819453f4ad6f3ccdaf618e


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2026-05-13 14:02 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-24 17:09 [PATCH] dir: use per-worktree repository ignore patterns upon request D. Ben Knoble
2026-04-24 19:35 ` brian m. carlson
2026-04-24 19:53 ` Phillip Wood
2026-04-25  3:06   ` Junio C Hamano
2026-05-08 14:14 ` [PATCH v2] ignore: note info/exclude lives in GIT_COMMON_DIR, not GIT_DIR D. Ben Knoble
2026-05-09 14:08   ` brian m. carlson
2026-05-11 10:30   ` Phillip Wood
2026-05-11 19:55     ` D. Ben Knoble
2026-05-12 21:21   ` [PATCH v3] " D. Ben Knoble
2026-05-13 14:02     ` Phillip Wood

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox