threads / patch / 64349

patch, 5 partsgit-add : Respect submodule ignore=all and only add changes with --force

Subject: [PATCH 0/5] git-add : Respect submodule ignore=all and only add changes with --force

## tl;dr

43 messages between Oct 18, 2025 and Mar 10, 2026. Diffs are folded; open one to read it.

replies: 42people: 6as markdown or json

Claus Schneider via GitGitGadget· Oct 18, 2025, 20:07 UTC · lore

The feature of configuring a submodule to "ignore=all" is nicely respected in commands "status" and "diff". However the "add" command does not respect the configuration the same way. The behavior is problematic for the logic between status/diff and add. Secondly it makes it problematic to track branches in the submodule configuration as developers unintentionally keeps add submodule updates and get conflicts for no intentional reason. Both adds unnecessary friction to the usage of submodules.

The patches implement the same logical behavior for ignore=all submodules as regular ignored files. The status now does not show any diff - nor will the add command update the reference submodule reference. If you add the submodule path which is ignore=all then you are presented with a message that you need to use the --force option. The branch=, ignore=all (and update=none) now works great with update --remote, but developers does not have to consider changes in the updates of the submodule sha1. The implementation removes a friction of working with submodules and can be used like the repo tool with branches configured. The submodule status report could be used for build/release documentation for reproduction of a setup.

A few tests used the adding of submodules without --force, hence they have been updated to use the --force option.

Claus Schneider(Eficode) (5):
  read-cache: update add_files_to_cache to take param
    ignored_too(--force)
  read-cache: let read-cache respect submodule ignore=all and --force
  tests: add new t2206-add-submodule-ignored.sh to test ignore=all
    scenario
  tests: fix existing tests when add an ignore=all submodule
  Documentation: update add --force and submodule ignore=all config
 Documentation/git-add.adoc       |   4 +-
 Documentation/gitmodules.adoc    |   5 +-
 builtin/add.c                    |   2 +-
 builtin/checkout.c               |   2 +-
 builtin/commit.c                 |   2 +-
 read-cache-ll.h                  |   2 +-
 read-cache.c                     |  54 ++++++++++++-
 t/lib-submodule-update.sh        |   6 +-
 t/meson.build                    |   1 +
 t/t2206-add-submodule-ignored.sh | 134 +++++++++++++++++++++++++++++++
 t/t7508-status.sh                |   2 +-
 11 files changed, 202 insertions(+), 12 deletions(-)
 create mode 100755 t/t2206-add-submodule-ignored.sh
base-commit: c44beea485f0f2feaf460e2ac87fdd5608d63cf0
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-1987%2FPraqma%2Frespect-submodule-ignore-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-1987/Praqma/respect-submodule-ignore-v1
Pull-Request: https://github.com/gitgitgadget/git/pull/1987
-- 
gitgitgadget
Claus Schneider(Eficode) via GitGitGadget· Oct 18, 2025, 20:07 UTC · re: Claus Schneider via GitGitGadget · lore

[PATCH 1/5] read-cache: update add_files_to_cache to take param ignored_too(--force)

From: "Claus Schneider(Eficode)" <claus.schneider@eficode.com>

The ignored_too parameter is added to the function add_files_to_cache for usage of explicit updating the index for the updated submodule using the explicit patchspec to the submodule.

Signed-off-by: Claus Schneider(Eficode) <claus.schneider@eficode.com>
---
 builtin/add.c      | 2 +-
 builtin/checkout.c | 2 +-
 builtin/commit.c   | 2 +-
 read-cache-ll.h    | 2 +-
 read-cache.c       | 8 +++++++-
 5 files changed, 11 insertions(+), 5 deletions(-)
Show changes to 5 files +11 −5

builtin/add.c, builtin/checkout.c, builtin/commit.c, read-cache-ll.h, read-cache.c

diff --git a/builtin/add.c b/builtin/add.c
index 0235854f80..cd1116e70a 100644
--- a/builtin/add.c
+++ b/builtin/add.c
@@ -582,7 +582,7 @@ int cmd_add(int argc,
 	else
 		exit_status |= add_files_to_cache(repo, prefix,
 						  &pathspec, ps_matched,
-						  include_sparse, flags);
+						  include_sparse, flags, ignored_too);
 
 	if (take_worktree_changes && !add_renormalize && !ignore_add_errors &&
 	    report_path_error(ps_matched, &pathspec))
diff --git a/builtin/checkout.c b/builtin/checkout.c
index f9453473fe..b2a404051d 100644
--- a/builtin/checkout.c
+++ b/builtin/checkout.c
@@ -899,7 +899,7 @@ static int merge_working_tree(const struct checkout_opts *opts,
 			 */
 
 			add_files_to_cache(the_repository, NULL, NULL, NULL, 0,
-					   0);
+					   0, 0 );
 			init_ui_merge_options(&o, the_repository);
 			o.verbosity = 0;
 			work = write_in_core_index_as_tree(the_repository);
diff --git a/builtin/commit.c b/builtin/commit.c
index b5b9608813..5bf7ae5fc1 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -455,7 +455,7 @@ static const char *prepare_index(const char **argv, const char *prefix,
 		repo_hold_locked_index(the_repository, &index_lock,
 				       LOCK_DIE_ON_ERROR);
 		add_files_to_cache(the_repository, also ? prefix : NULL,
-				   &pathspec, ps_matched, 0, 0);
+				   &pathspec, ps_matched, 0, 0, 0 );
 		if (!all && report_path_error(ps_matched, &pathspec))
 			exit(128);
 
diff --git a/read-cache-ll.h b/read-cache-ll.h
index 71b49d9af4..2c8b4b21b1 100644
--- a/read-cache-ll.h
+++ b/read-cache-ll.h
@@ -481,7 +481,7 @@ int cmp_cache_name_compare(const void *a_, const void *b_);
 
 int add_files_to_cache(struct repository *repo, const char *prefix,
 		       const struct pathspec *pathspec, char *ps_matched,
-		       int include_sparse, int flags);
+		       int include_sparse, int flags, int ignored_too );
 
 void overlay_tree_on_index(struct index_state *istate,
 			   const char *tree_name, const char *prefix);
diff --git a/read-cache.c b/read-cache.c
index 06ad74db22..56a3ef424c 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -3880,9 +3880,12 @@ void overlay_tree_on_index(struct index_state *istate,
 
 struct update_callback_data {
 	struct index_state *index;
+	struct repository *repo;
+	struct pathspec *pathspec;
 	int include_sparse;
 	int flags;
 	int add_errors;
+	int ignored_too;
 };
 
 static int fix_unmerged_status(struct diff_filepair *p,
@@ -3945,7 +3948,7 @@ static void update_callback(struct diff_queue_struct *q,
 
 int add_files_to_cache(struct repository *repo, const char *prefix,
 		       const struct pathspec *pathspec, char *ps_matched,
-		       int include_sparse, int flags)
+		       int include_sparse, int flags, int ignored_too )
 {
 	struct update_callback_data data;
 	struct rev_info rev;
@@ -3954,6 +3957,9 @@ int add_files_to_cache(struct repository *repo, const char *prefix,
 	data.index = repo->index;
 	data.include_sparse = include_sparse;
 	data.flags = flags;
+	data.repo = repo;
+	data.ignored_too = ignored_too;
+	data.pathspec = (struct pathspec *)pathspec;
 
 	repo_init_revisions(repo, &rev, prefix);
 	setup_revisions(0, NULL, &rev, NULL);
-- 
gitgitgadget
Claus Schneider(Eficode) via GitGitGadget· Oct 18, 2025, 20:07 UTC · re: Claus Schneider via GitGitGadget · lore

[PATCH 2/5] read-cache: let read-cache respect submodule ignore=all and --force

From: "Claus Schneider(Eficode)" <claus.schneider@eficode.com>

Given the submdule configuration is ignore=all then only update the submdule if the --force option is given and the submodule is explicit given in the pathspec.

A message is printed (like ignored files) guiding the user to use the --force flag if the user has explicitely want to update the submodule reference.

The reason for the change is support submodule branch tracking or similar and git status state nothing and git add should not add either. The workflow is more logic and similar to regular ignored files even the submodule is already tracked.

The change opens up a lot of possibilities for submodules to be used more freely and a like the repo tool. A submodule can be added for many more reason and loosely coupled dependencies to the super repo which often gives the friction of handle the explicit commits and updates without the need for tracking the submodule sha1 by sha1.

Signed-off-by: Claus Schneider(Eficode) <claus.schneider@eficode.com>
---
 read-cache.c | 46 +++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 45 insertions(+), 1 deletion(-)
Show changes to read-cache.c +45 −1
diff --git a/read-cache.c b/read-cache.c
index 56a3ef424c..3e87d03518 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -48,6 +48,8 @@
 #include "csum-file.h"
 #include "promisor-remote.h"
 #include "hook.h"
+#include "submodule.h"
+#include "submodule-config.h"
 
 /* Mask for the name length in ce_flags in the on-disk index */
 
@@ -3927,13 +3929,55 @@ static void update_callback(struct diff_queue_struct *q,
 		default:
 			die(_("unexpected diff status %c"), p->status);
 		case DIFF_STATUS_MODIFIED:
-		case DIFF_STATUS_TYPE_CHANGED:
+		case DIFF_STATUS_TYPE_CHANGED: {
+			struct stat st;
+			if (!lstat(path, &st) && S_ISDIR(st.st_mode)) { // only consider submodule if it is a directory
+				const struct submodule *sub = submodule_from_path(data->repo, null_oid(the_hash_algo), path);
+				if (sub && sub->name && sub->ignore && !strcmp(sub->ignore, "all")) {
+					int pathspec_matches = 0;
+					char *norm_pathspec = NULL;
+					int ps_i;
+					trace_printf("ignore=all %s\n", path);
+					trace_printf("pathspec %s\n",
+							(data->pathspec && data->pathspec->nr) ? "has pathspec" : "no pathspec");
+					/* Safely scan all pathspec items (q->nr may exceed pathspec->nr). */
+					if (data->pathspec) {
+						for (ps_i = 0; ps_i < data->pathspec->nr; ps_i++) {
+							const char *m = data->pathspec->items[ps_i].match;
+							if (!m)
+								continue;
+							norm_pathspec = xstrdup(m);
+							strip_dir_trailing_slashes(norm_pathspec);
+							if (!strcmp(path, norm_pathspec)) {
+								pathspec_matches = 1;
+								FREE_AND_NULL(norm_pathspec);
+								break;
+							}
+							FREE_AND_NULL(norm_pathspec);
+						}
+					}
+					if (pathspec_matches) {
+						if (data->ignored_too && data->ignored_too > 0) {
+							trace_printf("Forcing add of submodule ignored=all due to --force: %s\n", path);
+						} else {
+							printf(_("Skipping submodule due to ignore=all: %s"), path);
+							printf(_("Use -f if you really want to add them.") );
+							continue;
+						}
+					} else {
+						/* No explicit pathspec match -> skip silently (or with trace). */
+						trace_printf("pathspec does not match %s\n", path);
+						continue;
+					}
+				}
+			}
 			if (add_file_to_index(data->index, path, data->flags)) {
 				if (!(data->flags & ADD_CACHE_IGNORE_ERRORS))
 					die(_("updating files failed"));
 				data->add_errors++;
 			}
 			break;
+		}
 		case DIFF_STATUS_DELETED:
 			if (data->flags & ADD_CACHE_IGNORE_REMOVAL)
 				break;
-- 
gitgitgadget
Claus Schneider(Eficode) via GitGitGadget· Oct 18, 2025, 20:07 UTC · re: Claus Schneider via GitGitGadget · lore

[PATCH 3/5] tests: add new t2206-add-submodule-ignored.sh to test ignore=all scenario

From: "Claus Schneider(Eficode)" <claus.schneider@eficode.com>

The tests verify that the submodule behavior is intact and updating the config with ignore=all also behaves as intended with configuration in .gitmodules and configuration given on the command line.

Testfile is added to meson.build for execution.
Signed-off-by: Claus Schneider(Eficode) <claus.schneider@eficode.com>
---
 t/meson.build                    |   1 +
 t/t2206-add-submodule-ignored.sh | 134 +++++++++++++++++++++++++++++++
 2 files changed, 135 insertions(+)
 create mode 100755 t/t2206-add-submodule-ignored.sh
Show changes to 2 files +135 −0

t/meson.build, t/t2206-add-submodule-ignored.sh

diff --git a/t/meson.build b/t/meson.build
index bbeba1a8d5..1a6fb7edb2 100644
--- a/t/meson.build
+++ b/t/meson.build
@@ -281,6 +281,7 @@ integration_tests = [
   't2203-add-intent.sh',
   't2204-add-ignored.sh',
   't2205-add-worktree-config.sh',
+  't2206-add-submodule-ignored.sh',
   't2300-cd-to-toplevel.sh',
   't2400-worktree-add.sh',
   't2401-worktree-prune.sh',
diff --git a/t/t2206-add-submodule-ignored.sh b/t/t2206-add-submodule-ignored.sh
new file mode 100755
index 0000000000..77f7b0ebbc
--- /dev/null
+++ b/t/t2206-add-submodule-ignored.sh
@@ -0,0 +1,134 @@
+#!/bin/sh
+# shellcheck disable=SC2016
+
+# shellcheck disable=SC2034
+test_description='git add respects submodule ignore=all and explicit pathspec'
+
+# This test covers the behavior of "git add", "git status" and "git log" when
+# dealing with submodules that have the ignore=all setting in
+# .gitmodules. It ensures that changes in such submodules are
+# ignored by default, but can be staged with "git add --force".
+
+# shellcheck disable=SC1091
+. ./test-lib.sh
+
+GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
+export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
+
+base_path=$(pwd -P)
+
+#1
+test_expect_success 'setup: create origin repos'  '
+	cd "${base_path}" &&
+	git config --global protocol.file.allow always &&
+	git init sub &&
+		pwd &&
+		cd sub &&
+		test_commit sub_file1 &&
+		git tag v1.0 &&
+		test_commit sub_file2 &&
+		git tag v2.0 &&
+		test_commit sub_file3 &&
+		git tag v3.0 &&
+	cd "${base_path}" &&
+	git init main &&
+		cd main &&
+		test_commit first &&
+	cd "${base_path}"
+'
+#2
+# add submodule with default config (ignore=none) and
+# check log that is contains a path entry for the submodule 'sub'
+# change the commit in the submodule and check that 'git status' shows it as modified
+test_expect_success 'main: add submodule with default config'  '
+	cd "${base_path}" &&
+	cd main &&
+	git submodule add ../sub &&
+	git commit -m "add submodule" &&
+	git log --oneline --name-only | grep "^sub$" &&
+	git -C sub reset --hard v2.0 &&
+	git status --porcelain | grep "^ M sub$" &&
+	echo
+'
+#3
+# change the submodule config to ignore=all and check that status and log do not show changes
+test_expect_success 'main: submodule config ignore=all'  '
+	cd "${base_path}" &&
+	cd main &&
+	git config -f .gitmodules submodule.sub.ignore all &&
+	GIT_TRACE=1 git add . &&
+	git commit -m "update submodule config sub.ignore all" &&
+	! git status --porcelain | grep "^.*$" &&
+	! git log --oneline --name-only | grep "^sub$" &&
+	echo
+'
+#4
+# change the commit in the submodule and check that 'git status' does not show it as modified
+# but 'git status --ignore-submodules=none' does show it as modified
+test_expect_success 'sub: change to different sha1 and check status in main'  '
+	cd "${base_path}" &&
+	cd main &&
+	git -C sub reset --hard v1.0 &&
+	! git status --porcelain | grep "^ M sub$" &&
+	git status --ignore-submodules=none --porcelain | grep "^ M sub$" &&
+	echo
+'
+
+#5
+# check that normal 'git add' does not stage the change in the submodule
+test_expect_success 'main: check normal add and status'  '
+	cd "${base_path}" &&
+	cd main &&
+	GIT_TRACE=1 git add . &&
+	! git status --porcelain | grep "^ M sub$" &&
+	echo
+'
+
+#6
+# check that 'git add --force .' does not stage the change in the submodule
+# and that 'git status' does not show it as modified
+test_expect_success 'main: check --force add . and status'  '
+	cd "${base_path}" &&
+	cd main &&
+	GIT_TRACE=1 git add --force . &&
+	! git status --porcelain | grep "^M  sub$" &&
+	echo
+'
+
+#7
+# check that 'git add .' does not stage the change in the submodule
+# and that 'git status' does not show it as modified
+test_expect_success 'main: check _add sub_ and status'  '
+	cd "${base_path}" &&
+	cd main &&
+	GIT_TRACE=1 git add sub | grep "Skipping submodule due to ignore=all: sub" &&
+	! git status --porcelain | grep "^M  sub$" &&
+	echo
+'
+
+#8
+# check that 'git add --force sub' does stage the change in the submodule
+# check that 'git add --force ./sub/' does stage the change in the submodule
+# and that 'git status --porcelain' does show it as modified
+# commit it..
+# check that 'git log --ignore-submodules=none' shows the submodule change
+# in the log
+test_expect_success 'main: check force add sub and ./sub/ and status'  '
+	cd "${base_path}" &&
+	cd main &&
+	echo "Adding with --force should work: git add --force sub" &&
+	GIT_TRACE=1 git add --force sub &&
+	git status --porcelain | grep "^M  sub$" &&
+	git restore --staged sub &&
+	! git status --porcelain | grep "^M  sub$" &&
+	echo "Adding with --force should work: git add --force ./sub/" &&
+	GIT_TRACE=1 git add --force ./sub/ &&
+	git status --porcelain | grep "^M  sub$" &&
+	git commit -m "update submodule pointer" &&
+	! git status --porcelain | grep "^ M sub$" &&
+	git log --ignore-submodules=none --name-only --oneline | grep "^sub$" &&
+	echo
+'
+
+test_done
+exit 0
-- 
gitgitgadget
Claus Schneider(Eficode) via GitGitGadget· Oct 18, 2025, 20:07 UTC · re: Claus Schneider via GitGitGadget · lore

[PATCH 4/5] tests: fix existing tests when add an ignore=all submodule

From: "Claus Schneider(Eficode)" <claus.schneider@eficode.com>

There are tests that rely on "git add <submodule>" also adds it. A --force is needed with this enhancement hence they are added accordingly in these tests.

Updated tests:
- t1013-read-tree-submodule.sh ( fixed in: t/lib-submodule-update.sh )
- t7406-submodule-update.sh
- t7508-status.sh
Signed-off-by: Claus Schneider(Eficode) <claus.schneider@eficode.com>
---
 t/lib-submodule-update.sh | 6 +++---
 t/t7508-status.sh         | 2 +-
 2 files changed, 4 insertions(+), 4 deletions(-)
Show changes to 2 files +4 −4

t/lib-submodule-update.sh, t/t7508-status.sh

diff --git a/t/lib-submodule-update.sh b/t/lib-submodule-update.sh
index 36f767cb74..f591de6120 100644
--- a/t/lib-submodule-update.sh
+++ b/t/lib-submodule-update.sh
@@ -95,14 +95,14 @@ create_lib_submodule_repo () {
 			git commit -m "modified file2 and added file3" &&
 			git push origin modifications
 		) &&
-		git add sub1 &&
+		git add --force sub1 &&
 		git commit -m "Modify sub1" &&
 
 		git checkout -b add_nested_sub modify_sub1 &&
 		git -C sub1 checkout -b "add_nested_sub" &&
 		git -C sub1 submodule add --branch no_submodule ../submodule_update_sub2 sub2 &&
 		git -C sub1 commit -a -m "add a nested submodule" &&
-		git add sub1 &&
+		git add --force sub1 &&
 		git commit -a -m "update submodule, that updates a nested submodule" &&
 		git checkout -b modify_sub1_recursively &&
 		git -C sub1 checkout -b modify_sub1_recursively &&
@@ -112,7 +112,7 @@ create_lib_submodule_repo () {
 		git -C sub1/sub2 commit -m "make a change in nested sub" &&
 		git -C sub1 add sub2 &&
 		git -C sub1 commit -m "update nested sub" &&
-		git add sub1 &&
+		git add --force sub1 &&
 		git commit -m "update sub1, that updates nested sub" &&
 		git -C sub1 push origin modify_sub1_recursively &&
 		git -C sub1/sub2 push origin modify_sub1_recursively &&
diff --git a/t/t7508-status.sh b/t/t7508-status.sh
index cdc1d6fcc7..7617be14e8 100755
--- a/t/t7508-status.sh
+++ b/t/t7508-status.sh
@@ -1565,7 +1565,7 @@ test_expect_success 'git commit will commit a staged but ignored submodule' '
 
 test_expect_success 'git commit --dry-run will show a staged but ignored submodule' '
 	git reset HEAD^ &&
-	git add sm &&
+	git add --force sm &&
 	cat >expect << EOF &&
 On branch main
 Your branch and '\''upstream'\'' have diverged,
-- 
gitgitgadget
Claus Schneider(Eficode) via GitGitGadget· Oct 18, 2025, 20:07 UTC · re: Claus Schneider via GitGitGadget · lore

[PATCH 5/5] Documentation: update add --force and submodule ignore=all config

From: "Claus Schneider(Eficode)" <claus.schneider@eficode.com>
- The add --force doc: append additionel info about the submodule
functionality.
- The submodule config ignore=all now need --force in order to update
  the index.
Signed-off-by: Claus Schneider(Eficode) <claus.schneider@eficode.com>
---
 Documentation/git-add.adoc    | 4 +++-
 Documentation/gitmodules.adoc | 5 ++++-
 2 files changed, 7 insertions(+), 2 deletions(-)
Show changes to 2 files +7 −2

Documentation/git-add.adoc, Documentation/gitmodules.adoc

diff --git a/Documentation/git-add.adoc b/Documentation/git-add.adoc
index b7a735824d..2234b1e846 100644
--- a/Documentation/git-add.adoc
+++ b/Documentation/git-add.adoc
@@ -77,7 +77,9 @@ in linkgit:gitglossary[7].
 
 `-f`::
 `--force`::
-	Allow adding otherwise ignored files.
+	Allow adding otherwise ignored files. The option is also used
+	when updating submodules and `submodule.<name>.ignore=all`
+	is set. The `path` to the submodule must be explicitly specified.
 
 `--sparse`::
 	Allow updating index entries outside of the sparse-checkout cone.
diff --git a/Documentation/gitmodules.adoc b/Documentation/gitmodules.adoc
index d9bec8b187..3aa71170ee 100644
--- a/Documentation/gitmodules.adoc
+++ b/Documentation/gitmodules.adoc
@@ -70,7 +70,10 @@ submodule.<name>.ignore::
 --
 	all;; The submodule will never be considered modified (but will
 	    nonetheless show up in the output of status and commit when it has
-	    been staged).
+	    been staged). Add `(new commits)` can be overruled using the
+	    `git add --force <submodule.path>` similar to ignored files. The setting has effect
+	    for `status`, `update-index`, `diff` and `log`(due to underlaying
+	    `diff`)
 
 	dirty;; All changes to the submodule's work tree will be ignored, only
 	    committed differences between the `HEAD` of the submodule and its
-- 
gitgitgadget
Phillip Wood· Oct 19, 2025, 15:34 UTC · re: Claus Schneider via GitGitGadget · lore

Re: [PATCH 0/5] git-add : Respect submodule ignore=all and only add changes with --force

Hi Claus
[I've adjusted the CC list slightly]
On 18/10/2025 21:07, Claus Schneider via GitGitGadget wrote:
> The feature of configuring a submodule to "ignore=all" is nicely respected
> in commands "status" and "diff". However the "add" command does not respect
> the configuration the same way.

I was curious why, when "git add" uses the same machinery as "git diff" to figure out which paths need updating, it behaves differently. It turns out that add_files_to_cache() contains

	rev.diffopt.flags.override_submodule_config = 1;

which makes "git add" ignore "submodule.<name>.ignore". Tracing the history of this line, it originates from 5556808690e (add, reset: ensure submodules can be added or reset, 2017-07-25) which made a deliberate choice for both "git add" and "git reset" not to behave like "git diff". If we're going to change the behavior then it would be helpful to explain how this patch series ameliorates the concerns that lead to that commit and why it is sensible to change the behavior of "git add" but not "git reset". It also suggests that a much simpler way of implementing the change would be to delete that line.

I'm not convinced that the approach of using "--force" is a good idea as it conflates ignoring changes to tracked paths (which is what submodule.<name>.ignore" does) with ignoring untracked paths (which is what ".gitignore" does). If we're happy to break existing uses that rely on the current behavior then having a new option to override submodule.<name>.ignore strikes me as a better way forward. I don't have much experience of using submodules so I can't comment on whether changing the behavior is a good idea or not.

Thanks
Phillip
  The behavior is problematic for the logic
Show 47 quoted lines
> between status/diff and add. Secondly it makes it problematic to track
> branches in the submodule configuration as developers unintentionally keeps
> add submodule updates and get conflicts for no intentional reason. Both adds
> unnecessary friction to the usage of submodules.
> 
> The patches implement the same logical behavior for ignore=all submodules as
> regular ignored files. The status now does not show any diff - nor will the
> add command update the reference submodule reference. If you add the
> submodule path which is ignore=all then you are presented with a message
> that you need to use the --force option. The branch=, ignore=all (and
> update=none) now works great with update --remote, but developers does not
> have to consider changes in the updates of the submodule sha1. The
> implementation removes a friction of working with submodules and can be used
> like the repo tool with branches configured. The submodule status report
> could be used for build/release documentation for reproduction of a setup.
> 
> A few tests used the adding of submodules without --force, hence they have
> been updated to use the --force option.
> 
> Claus Schneider(Eficode) (5):
>    read-cache: update add_files_to_cache to take param
>      ignored_too(--force)
>    read-cache: let read-cache respect submodule ignore=all and --force
>    tests: add new t2206-add-submodule-ignored.sh to test ignore=all
>      scenario
>    tests: fix existing tests when add an ignore=all submodule
>    Documentation: update add --force and submodule ignore=all config
> 
>   Documentation/git-add.adoc       |   4 +-
>   Documentation/gitmodules.adoc    |   5 +-
>   builtin/add.c                    |   2 +-
>   builtin/checkout.c               |   2 +-
>   builtin/commit.c                 |   2 +-
>   read-cache-ll.h                  |   2 +-
>   read-cache.c                     |  54 ++++++++++++-
>   t/lib-submodule-update.sh        |   6 +-
>   t/meson.build                    |   1 +
>   t/t2206-add-submodule-ignored.sh | 134 +++++++++++++++++++++++++++++++
>   t/t7508-status.sh                |   2 +-
>   11 files changed, 202 insertions(+), 12 deletions(-)
>   create mode 100755 t/t2206-add-submodule-ignored.sh
> 
> 
> base-commit: c44beea485f0f2feaf460e2ac87fdd5608d63cf0
> Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-1987%2FPraqma%2Frespect-submodule-ignore-v1
> Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-1987/Praqma/respect-submodule-ignore-v1
> Pull-Request: https://github.com/gitgitgadget/git/pull/1987
Claus Schneider· Oct 20, 2025, 07:28 UTC · lore

Re: [PATCH 0/5] git-add : Respect submodule ignore=all and only add changes with --force

Hi again ..

I have read the documentation for submodule and reset. See from a non-git-developer it is actually pretty hard to understand what happens with regards to the "reset" command.

The only hint I can find which does not mean a lot to an ordinary user:
- "Defines under what circumstances "git status" and the diff family
show a submodule as modified".
- GPT-5 does not say anything regarding "reset", if asked a few levels
of "/explains" regarding "diff family". I find the documentation
inconclusive as an end-user.
- Looking at the "reset" --help it does only talk about
--[no-]recurse-submodules but not really what the ignore=all
- I can find the override_submodule_config=1 in reset, commit, status,
add-interactive, read-cache.
.. so I am a bit confused.
From an end-user perspective I would expect this of "all":
- (pre-action): "status" and "diff-of-workspace/staging". It should
respect ignore=all unless overridden or explicit specified
- (action): "add" : It should respect ignore=all unless overridden or
explicit specified(--force)
- (action): "reset", "restore" ..<etc>: It should respect ignore=all
unless overridden or explicit specified and leave it to submodules
--init / --remote
- (action): "clean": It could be argued of the -x option should also
act on submodules - but fair to leave it to submodules --init /
--remote
- (post-action) "diff-of-history", "log" (aka <ref1> <ref2> ) : It
should always tell what happened in history (git-graph) despite what
the current .gitmodules states regards to ignore=all

It could be a new option value should be added like "always" or "logical" respectively the above and then leave the "all" to the current behavior.

Best regards Claus

On Sun, Oct 19, 2025 at 11:55 PM Claus Schneider <claus.schneider@eficode.com> wrote:

Show 104 quoted lines
>
> Hi Philip ..
>
> Thank you for your feedback and for investigating this. I was not aware of the setting that causes `add` and `reset` to override submodule configuration, and I will need to look into `reset` further.
>
> I understand the problematic aspect of not being able to add an update of a submodule reference, which likely led to the overwrite setting. From a Git developer's perspective, always adding it might have seemed like the simplest approach.
>
> However, from an end-user perspective, it's not logical for `status` to show nothing while `add` has an effect. A more intuitive workflow would align with how ignored files are handled even though it is already tracked.
>
> My patch implements what I believe should have been in the first place. My implementation still needs the `overwrite=1` set in order to get the diff files list so I can 'operate' on it and make the `--force` logic like the ignore files.
>
> Best regards
> Claus
>
> On Sun, Oct 19, 2025, 17:34 Phillip Wood <phillip.wood123@gmail.com> wrote:
>>
>> Hi Claus
>>
>> [I've adjusted the CC list slightly]
>>
>> On 18/10/2025 21:07, Claus Schneider via GitGitGadget wrote:
>> > The feature of configuring a submodule to "ignore=all" is nicely respected
>> > in commands "status" and "diff". However the "add" command does not respect
>> > the configuration the same way.
>>
>> I was curious why, when "git add" uses the same machinery as "git diff"
>> to figure out which paths need updating, it behaves differently. It
>> turns out that add_files_to_cache() contains
>>
>>         rev.diffopt.flags.override_submodule_config = 1;
>>
>> which makes "git add" ignore "submodule.<name>.ignore". Tracing the
>> history of this line, it originates from 5556808690e (add, reset: ensure
>> submodules can be added or reset, 2017-07-25) which made a deliberate
>> choice for both "git add" and "git reset" not to behave like "git diff".
>> If we're going to change the behavior then it would be helpful to
>> explain how this patch series ameliorates the concerns that lead to that
>> commit and why it is sensible to change the behavior of "git add" but
>> not "git reset". It also suggests that a much simpler way of
>> implementing the change would be to delete that line.
>>
>> I'm not convinced that the approach of using "--force" is a good idea as
>> it conflates ignoring changes to tracked paths (which is what
>> submodule.<name>.ignore" does) with ignoring untracked paths (which is
>> what ".gitignore" does). If we're happy to break existing uses that rely
>> on the current behavior then having a new option to override
>> submodule.<name>.ignore strikes me as a better way forward. I don't have
>> much experience of using submodules so I can't comment on whether
>> changing the behavior is a good idea or not.
>>
>> Thanks
>>
>> Phillip
>>
>>
>>   The behavior is problematic for the logic
>> > between status/diff and add. Secondly it makes it problematic to track
>> > branches in the submodule configuration as developers unintentionally keeps
>> > add submodule updates and get conflicts for no intentional reason. Both adds
>> > unnecessary friction to the usage of submodules.
>> >
>> > The patches implement the same logical behavior for ignore=all submodules as
>> > regular ignored files. The status now does not show any diff - nor will the
>> > add command update the reference submodule reference. If you add the
>> > submodule path which is ignore=all then you are presented with a message
>> > that you need to use the --force option. The branch=, ignore=all (and
>> > update=none) now works great with update --remote, but developers does not
>> > have to consider changes in the updates of the submodule sha1. The
>> > implementation removes a friction of working with submodules and can be used
>> > like the repo tool with branches configured. The submodule status report
>> > could be used for build/release documentation for reproduction of a setup.
>> >
>> > A few tests used the adding of submodules without --force, hence they have
>> > been updated to use the --force option.
>> >
>> > Claus Schneider(Eficode) (5):
>> >    read-cache: update add_files_to_cache to take param
>> >      ignored_too(--force)
>> >    read-cache: let read-cache respect submodule ignore=all and --force
>> >    tests: add new t2206-add-submodule-ignored.sh to test ignore=all
>> >      scenario
>> >    tests: fix existing tests when add an ignore=all submodule
>> >    Documentation: update add --force and submodule ignore=all config
>> >
>> >   Documentation/git-add.adoc       |   4 +-
>> >   Documentation/gitmodules.adoc    |   5 +-
>> >   builtin/add.c                    |   2 +-
>> >   builtin/checkout.c               |   2 +-
>> >   builtin/commit.c                 |   2 +-
>> >   read-cache-ll.h                  |   2 +-
>> >   read-cache.c                     |  54 ++++++++++++-
>> >   t/lib-submodule-update.sh        |   6 +-
>> >   t/meson.build                    |   1 +
>> >   t/t2206-add-submodule-ignored.sh | 134 +++++++++++++++++++++++++++++++
>> >   t/t7508-status.sh                |   2 +-
>> >   11 files changed, 202 insertions(+), 12 deletions(-)
>> >   create mode 100755 t/t2206-add-submodule-ignored.sh
>> >
>> >
>> > base-commit: c44beea485f0f2feaf460e2ac87fdd5608d63cf0
>> > Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-1987%2FPraqma%2Frespect-submodule-ignore-v1
>> > Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-1987/Praqma/respect-submodule-ignore-v1
>> > Pull-Request: https://github.com/gitgitgadget/git/pull/1987
>>
Phillip Wood· Oct 24, 2025, 13:55 UTC · lore

Re: [PATCH 0/5] git-add : Respect submodule ignore=all and only add changes with --force

Hi Claus
On 19/10/2025 22:39, Claus Schneider wrote:
Show 13 quoted lines
> On Sun, Oct 19, 2025, 17:34 Phillip Wood <phillip.wood123@gmail.com 
> <mailto:phillip.wood123@gmail.com>> wrote:
> 
>> I was curious why, when "git add" uses the same machinery as "git diff"
>> to figure out which paths need updating, it behaves differently. It
>> turns out that add_files_to_cache() contains
>> 
>>           rev.diffopt.flags.override_submodule_config = 1;
>> 
>> which makes "git add" ignore "submodule.<name>.ignore". Tracing the
>> history of this line, it originates from 5556808690e (add, reset: ensure
>> submodules can be added or reset, 2017-07-25) which made a deliberate
>> choice for both "git add" and "git reset" not to behave like "git diff".
> Thank you for your feedback and for investigating this. I was not aware > of the setting that causes `add` and `reset` to override submodule 
> configuration, and I will need to look into `reset` further.

You should mention the commit that added the current behavior and the reason it was added in the commit message where you change the behavior.

Show 7 quoted lines
> I understand the problematic aspect of not being able to add an update 
> of a submodule reference, which likely led to the overwrite setting. 
> From a Git developer's perspective, always adding it might have seemed 
> like the simplest approach.
> 
> However, from an end-user perspective, it's not logical for `status` to 
> show nothing while `add` has an effect. 

I'm quite sympathetic to this view, I think you should explain this in the commit message where you change the behavior and see what others think.

> A more intuitive workflow would 
> align with how ignored files are handled even though it is already tracked.

As I said before do not think conflating ignoring changes to tracked files with ignoring files is a good idea. The two are fundamentally different because ignored files are not tracked. I would suggest adding a new option such as "--include-ignored-submodules" instead of piggybacking on "--force". Using a different option also means that user's will not accidentally stage ignored files when they're trying to stage a submodule whose changes are normally ignored.

> My patch implements what I believe should have been in the first place. 
> My implementation still needs the `overwrite=1` set in order to get the 
> diff files list so I can 'operate' on it and make the `--force` logic 
> like the ignore files.

Oh, you're right, if we want to print a warning we will need to keep overriding the submodule config.

Hopefully someone with more experience of submodules will be able to review the code soon.

Thanks
Phillip
Claus Schneider· Nov 13, 2025, 12:51 UTC · re: Phillip Wood · lore

Re: [PATCH 0/5] git-add : Respect submodule ignore=all and only add changes with --force

Thanks for the feedback and suggestions.

I have now implemented the --include-ignored-submodules option instead of --force. I have also extended the commit messages with more reasoning.

? Is it best to have a single commit with everything or a set of commit for each part of the solution

? How do I update the patches with the modifications accordingly ( from GitGadget PR with a new /submit ) ?

Thanks in advance Claus Schneider

On Fri, Oct 24, 2025 at 3:55 PM Phillip Wood <phillip.wood123@gmail.com> wrote:
Show 60 quoted lines
>
> Hi Claus
>
> On 19/10/2025 22:39, Claus Schneider wrote:
> > On Sun, Oct 19, 2025, 17:34 Phillip Wood <phillip.wood123@gmail.com
> > <mailto:phillip.wood123@gmail.com>> wrote:
> >
> >> I was curious why, when "git add" uses the same machinery as "git diff"
> >> to figure out which paths need updating, it behaves differently. It
> >> turns out that add_files_to_cache() contains
> >>
> >>           rev.diffopt.flags.override_submodule_config = 1;
> >>
> >> which makes "git add" ignore "submodule.<name>.ignore". Tracing the
> >> history of this line, it originates from 5556808690e (add, reset: ensure
> >> submodules can be added or reset, 2017-07-25) which made a deliberate
> >> choice for both "git add" and "git reset" not to behave like "git diff".
>
> > Thank you for your feedback and for investigating this. I was not aware > of the setting that causes `add` and `reset` to override submodule
> > configuration, and I will need to look into `reset` further.
>
> You should mention the commit that added the current behavior and the
> reason it was added in the commit message where you change the behavior.
>
> > I understand the problematic aspect of not being able to add an update
> > of a submodule reference, which likely led to the overwrite setting.
> > From a Git developer's perspective, always adding it might have seemed
> > like the simplest approach.
> >
> > However, from an end-user perspective, it's not logical for `status` to
> > show nothing while `add` has an effect.
>
> I'm quite sympathetic to this view, I think you should explain this in the
> commit message where you change the behavior and see what others think.
>
> > A more intuitive workflow would
> > align with how ignored files are handled even though it is already tracked.
>
> As I said before do not think conflating ignoring changes to tracked files
> with ignoring files is a good idea. The two are fundamentally different
> because ignored files are not tracked. I would suggest adding a new option
> such as "--include-ignored-submodules" instead of piggybacking on "--force".
> Using a different option also means that user's will not accidentally stage
> ignored files when they're trying to stage a submodule whose changes are
> normally ignored.
>
> > My patch implements what I believe should have been in the first place.
> > My implementation still needs the `overwrite=1` set in order to get the
> > diff files list so I can 'operate' on it and make the `--force` logic
> > like the ignore files.
>
> Oh, you're right, if we want to print a warning we will need to keep
> overriding the submodule config.
>
> Hopefully someone with more experience of submodules will be able to review
> the code soon.
>
> Thanks
>
> Phillip
Claus Schneider via GitGitGadget· Nov 13, 2025, 18:10 UTC · re: Claus Schneider via GitGitGadget · lore

[PATCH v2 0/5] git-add : Respect submodule ignore=all and only add changes with --force

The feature of configuring a submodule to "ignore=all" is nicely respected in commands "status" and "diff". However the "add" command does not respect the configuration the same way. The behavior is problematic for the logic between status/diff and add. Secondly it makes it problematic to track branches in the submodule configuration as developers unintentionally keeps add submodule updates and get conflicts for no intentional reason. Both adds unnecessary friction to the usage of submodules.

The patches implement the same logical behavior for ignore=all submodules as regular ignored files. The status now does not show any diff - nor will the add command update the reference submodule reference. If you add the submodule path which is ignore=all then you are presented with a message that you need to use the --force option. The branch=, ignore=all (and update=none) now works great with update --remote, but developers does not have to consider changes in the updates of the submodule sha1. The implementation removes a friction of working with submodules and can be used like the repo tool with branches configured. The submodule status report could be used for build/release documentation for reproduction of a setup.

A few tests used the adding of submodules without --force, hence they have been updated to use the --force option.

Claus Schneider(Eficode) (5):
  read-cache: update add_files_to_cache take param
    include_ignored_submodules
  read-cache: add/read-cache respect submodule ignore=all
  tests: add new t2206-add-submodule-ignored.sh to test ignore=all
    scenario
  tests: fix existing tests when add an ignore=all submodule
  Documentation: add --include_ignored_submodules + ignore=all config
 .devcontainer/Dockerfile            |  70 +++++++++++++++
 .devcontainer/Dockerfile.standalone |  76 ++++++++++++++++
 .devcontainer/devcontainer.json     |  25 ++++++
 Documentation/config/submodule.adoc |  13 +--
 Documentation/git-add.adoc          |   5 ++
 Documentation/gitmodules.adoc       |   5 +-
 builtin/add.c                       |   4 +-
 builtin/checkout.c                  |   2 +-
 builtin/commit.c                    |   2 +-
 read-cache-ll.h                     |   2 +-
 read-cache.c                        |  54 ++++++++++-
 t/lib-submodule-update.sh           |   6 +-
 t/meson.build                       |   1 +
 t/t2206-add-submodule-ignored.sh    | 134 ++++++++++++++++++++++++++++
 t/t7508-status.sh                   |   2 +-
 15 files changed, 384 insertions(+), 17 deletions(-)
 create mode 100644 .devcontainer/Dockerfile
 create mode 100644 .devcontainer/Dockerfile.standalone
 create mode 100644 .devcontainer/devcontainer.json
 create mode 100755 t/t2206-add-submodule-ignored.sh
base-commit: 81f86aacc4eb74cdb9c2c8082d36d2070c666045
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-1987%2FPraqma%2Frespect-submodule-ignore-v2
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-1987/Praqma/respect-submodule-ignore-v2
Pull-Request: https://github.com/gitgitgadget/git/pull/1987
Range-diff vs v1:
 1:  d98cca698d ! 1:  5796009122 read-cache: update add_files_to_cache to take param ignored_too(--force)
     @@ Metadata
      Author: Claus Schneider(Eficode) <claus.schneider@eficode.com>
      
       ## Commit message ##
     -    read-cache: update add_files_to_cache to take param ignored_too(--force)
     +    read-cache: update add_files_to_cache take param include_ignored_submodules
      
     -    The ignored_too parameter is added to the function add_files_to_cache for
     -    usage of explicit updating the index for the updated submodule using the
     -    explicit patchspec to the submodule.
     +    The include_ignored_submodules parameter is added to the function
     +    add_files_to_cache for usage of explicit updating the index for the updated
     +    submodule using the explicit patchspec to the submodule.
      
          Signed-off-by: Claus Schneider(Eficode) <claus.schneider@eficode.com>
      
       ## builtin/add.c ##
     +@@ builtin/add.c: N_("The following paths are ignored by one of your .gitignore files:\n");
     + static int verbose, show_only, ignored_too, refresh_only;
     + static int ignore_add_errors, intent_to_add, ignore_missing;
     + static int warn_on_embedded_repo = 1;
     ++static int include_ignored_submodules;
     + 
     + #define ADDREMOVE_DEFAULT 1
     + static int addremove = ADDREMOVE_DEFAULT;
     +@@ builtin/add.c: static struct option builtin_add_options[] = {
     + 	OPT_BOOL( 0 , "ignore-errors", &ignore_add_errors, N_("just skip files which cannot be added because of errors")),
     + 	OPT_BOOL( 0 , "ignore-missing", &ignore_missing, N_("check if - even missing - files are ignored in dry run")),
     + 	OPT_BOOL(0, "sparse", &include_sparse, N_("allow updating entries outside of the sparse-checkout cone")),
     ++    OPT_BOOL(0, "include-ignored-submodules", &include_ignored_submodules, N_("add submodules even if they has configuration ignore=all")),
     + 	OPT_STRING(0, "chmod", &chmod_arg, "(+|-)x",
     + 		   N_("override the executable bit of the listed files")),
     + 	OPT_HIDDEN_BOOL(0, "warn-embedded-repo", &warn_on_embedded_repo,
      @@ builtin/add.c: int cmd_add(int argc,
       	else
       		exit_status |= add_files_to_cache(repo, prefix,
       						  &pathspec, ps_matched,
      -						  include_sparse, flags);
     -+						  include_sparse, flags, ignored_too);
     ++						  include_sparse, flags, include_ignored_submodules);
       
       	if (take_worktree_changes && !add_renormalize && !ignore_add_errors &&
       	    report_path_error(ps_matched, &pathspec))
     @@ read-cache.c: void overlay_tree_on_index(struct index_state *istate,
       	int include_sparse;
       	int flags;
       	int add_errors;
     -+	int ignored_too;
     ++	int include_ignored_submodules;
       };
       
       static int fix_unmerged_status(struct diff_filepair *p,
      @@ read-cache.c: static void update_callback(struct diff_queue_struct *q,
     + 		default:
     + 			die(_("unexpected diff status %c"), p->status);
     + 		case DIFF_STATUS_MODIFIED:
     +-		case DIFF_STATUS_TYPE_CHANGED:
     ++		case DIFF_STATUS_TYPE_CHANGED: {
     ++			struct stat st;
     ++			if (!lstat(path, &st) && S_ISDIR(st.st_mode)) { // only consider submodule if it is a directory
     ++				const struct submodule *sub = submodule_from_path(data->repo, null_oid(the_hash_algo), path);
     ++				if (sub && sub->name && sub->ignore && !strcmp(sub->ignore, "all")) {
     ++					int pathspec_matches = 0;
     ++					char *norm_pathspec = NULL;
     ++					int ps_i;
     ++					trace_printf("ignore=all %s\n", path);
     ++					trace_printf("pathspec %s\n",
     ++							(data->pathspec && data->pathspec->nr) ? "has pathspec" : "no pathspec");
     ++					/* Safely scan all pathspec items (q->nr may exceed pathspec->nr). */
     ++					if (data->pathspec) {
     ++						for (ps_i = 0; ps_i < data->pathspec->nr; ps_i++) {
     ++							const char *m = data->pathspec->items[ps_i].match;
     ++							if (!m)
     ++								continue;
     ++							norm_pathspec = xstrdup(m);
     ++							strip_dir_trailing_slashes(norm_pathspec);
     ++							if (!strcmp(path, norm_pathspec)) {
     ++								pathspec_matches = 1;
     ++								FREE_AND_NULL(norm_pathspec);
     ++								break;
     ++							}
     ++							FREE_AND_NULL(norm_pathspec);
     ++						}
     ++					}
     ++					if (pathspec_matches) {
     ++						if (data->include_ignored_submodules && data->include_ignored_submodules > 0) {
     ++							trace_printf("Add ignored=all submodule due to --include_ignored_submodules: %s\n", path);
     ++						} else {
     ++							printf(_("Skipping submodule due to ignore=all: %s"), path);
     ++							printf(_("Use --include_ignored_submodules, if you really want to add them.") );
     ++							continue;
     ++						}
     ++					} else {
     ++						/* No explicit pathspec match -> skip silently (or with trace). */
     ++						trace_printf("pathspec does not match %s\n", path);
     ++						continue;
     ++					}
     ++				}
     ++			}
     + 			if (add_file_to_index(data->index, path, data->flags)) {
     + 				if (!(data->flags & ADD_CACHE_IGNORE_ERRORS))
     + 					die(_("updating files failed"));
     +@@ read-cache.c: static void update_callback(struct diff_queue_struct *q,
       
       int add_files_to_cache(struct repository *repo, const char *prefix,
       		       const struct pathspec *pathspec, char *ps_matched,
      -		       int include_sparse, int flags)
     -+		       int include_sparse, int flags, int ignored_too )
     ++		       int include_sparse, int flags, int include_ignored_submodules )
       {
       	struct update_callback_data data;
       	struct rev_info rev;
     @@ read-cache.c: int add_files_to_cache(struct repository *repo, const char *prefix
       	data.include_sparse = include_sparse;
       	data.flags = flags;
      +	data.repo = repo;
     -+	data.ignored_too = ignored_too;
     ++	data.include_ignored_submodules = include_ignored_submodules;
      +	data.pathspec = (struct pathspec *)pathspec;
       
       	repo_init_revisions(repo, &rev, prefix);
 2:  d1b02617e6 ! 2:  9ec79b9a11 read-cache: let read-cache respect submodule ignore=all and --force
     @@ Metadata
      Author: Claus Schneider(Eficode) <claus.schneider@eficode.com>
      
       ## Commit message ##
     -    read-cache: let read-cache respect submodule ignore=all and --force
     +    read-cache: add/read-cache respect submodule ignore=all
      
     -    Given the submdule configuration is ignore=all then only update the
     -    submdule if the --force option is given and the submodule is explicit
     -    given in the pathspec.
     +    Submodules configured with ignore=all are now skipped during add operations
     +    unless overridden by --include-ignored-submodules and the submodule path is
     +    explicitly specified.
      
          A message is printed (like ignored files) guiding the user to use the
     -    --force flag if the user has explicitely want to update the submodule
     -    reference.
     +    --include-ignored-submodules flag if the user has explicitely want to update
     +    the submodule reference.
      
          The reason for the change is support submodule branch tracking or
          similar and git status state nothing and git add should not add either.
     @@ Commit message
          the submodule is already tracked.
      
          The change opens up a lot of possibilities for submodules to be used
     -    more freely and a like the repo tool. A submodule can be added for many
     +    more freely and simular to the repo tool. A submodule can be added for many
          more reason and loosely coupled dependencies to the super repo which often
          gives the friction of handle the explicit commits and updates without
          the need for tracking the submodule sha1 by sha1.
     @@ read-cache.c
       /* Mask for the name length in ce_flags in the on-disk index */
       
      @@ read-cache.c: static void update_callback(struct diff_queue_struct *q,
     - 		default:
     - 			die(_("unexpected diff status %c"), p->status);
     - 		case DIFF_STATUS_MODIFIED:
     --		case DIFF_STATUS_TYPE_CHANGED:
     -+		case DIFF_STATUS_TYPE_CHANGED: {
     -+			struct stat st;
     -+			if (!lstat(path, &st) && S_ISDIR(st.st_mode)) { // only consider submodule if it is a directory
     -+				const struct submodule *sub = submodule_from_path(data->repo, null_oid(the_hash_algo), path);
     -+				if (sub && sub->name && sub->ignore && !strcmp(sub->ignore, "all")) {
     -+					int pathspec_matches = 0;
     -+					char *norm_pathspec = NULL;
     -+					int ps_i;
     -+					trace_printf("ignore=all %s\n", path);
     -+					trace_printf("pathspec %s\n",
     -+							(data->pathspec && data->pathspec->nr) ? "has pathspec" : "no pathspec");
     -+					/* Safely scan all pathspec items (q->nr may exceed pathspec->nr). */
     -+					if (data->pathspec) {
     -+						for (ps_i = 0; ps_i < data->pathspec->nr; ps_i++) {
     -+							const char *m = data->pathspec->items[ps_i].match;
     -+							if (!m)
     -+								continue;
     -+							norm_pathspec = xstrdup(m);
     -+							strip_dir_trailing_slashes(norm_pathspec);
     -+							if (!strcmp(path, norm_pathspec)) {
     -+								pathspec_matches = 1;
     -+								FREE_AND_NULL(norm_pathspec);
     -+								break;
     -+							}
     -+							FREE_AND_NULL(norm_pathspec);
     -+						}
     -+					}
     -+					if (pathspec_matches) {
     -+						if (data->ignored_too && data->ignored_too > 0) {
     -+							trace_printf("Forcing add of submodule ignored=all due to --force: %s\n", path);
     -+						} else {
     -+							printf(_("Skipping submodule due to ignore=all: %s"), path);
     -+							printf(_("Use -f if you really want to add them.") );
     -+							continue;
     -+						}
     -+					} else {
     -+						/* No explicit pathspec match -> skip silently (or with trace). */
     -+						trace_printf("pathspec does not match %s\n", path);
     -+						continue;
     -+					}
     -+				}
     -+			}
     - 			if (add_file_to_index(data->index, path, data->flags)) {
     - 				if (!(data->flags & ADD_CACHE_IGNORE_ERRORS))
     - 					die(_("updating files failed"));
     + 					}
     + 					if (pathspec_matches) {
     + 						if (data->include_ignored_submodules && data->include_ignored_submodules > 0) {
     +-							trace_printf("Add ignored=all submodule due to --include_ignored_submodules: %s\n", path);
     ++							trace_printf("Add submodule due to --include_ignored_submodules: %s\n", path);
     + 						} else {
     + 							printf(_("Skipping submodule due to ignore=all: %s"), path);
     + 							printf(_("Use --include_ignored_submodules, if you really want to add them.") );
     +@@ read-cache.c: static void update_callback(struct diff_queue_struct *q,
     + 						}
     + 					} else {
     + 						/* No explicit pathspec match -> skip silently (or with trace). */
     +-						trace_printf("pathspec does not match %s\n", path);
     ++						trace_printf("Pathspec to submodule does not match explicitly: %s\n", path);
     + 						continue;
     + 					}
     + 				}
     +@@ read-cache.c: static void update_callback(struct diff_queue_struct *q,
       				data->add_errors++;
       			}
       			break;
 3:  8f3d5f7ec1 ! 3:  399a153b95 tests: add new t2206-add-submodule-ignored.sh to test ignore=all scenario
     @@ Commit message
          config with ignore=all also behaves as intended with configuration in
          .gitmodules and configuration given on the command line.
      
     -    Testfile is added to meson.build for execution.
     +    The usage of --include_ignored_submodules is showcased and tested in the
     +    test suite.
     +
     +    The test file is added to meson.build for execution.
      
          Signed-off-by: Claus Schneider(Eficode) <claus.schneider@eficode.com>
      
     @@ t/t2206-add-submodule-ignored.sh (new)
      +# This test covers the behavior of "git add", "git status" and "git log" when
      +# dealing with submodules that have the ignore=all setting in
      +# .gitmodules. It ensures that changes in such submodules are
     -+# ignored by default, but can be staged with "git add --force".
     ++# ignored by default, but can be staged with "git add --include-ignored-submodules".
      +
      +# shellcheck disable=SC1091
      +. ./test-lib.sh
     @@ t/t2206-add-submodule-ignored.sh (new)
      +'
      +
      +#6
     -+# check that 'git add --force .' does not stage the change in the submodule
     ++# check that 'git add --include-ignored-submodules .' does not stage the change in the submodule
      +# and that 'git status' does not show it as modified
     -+test_expect_success 'main: check --force add . and status'  '
     ++test_expect_success 'main: check --include-ignored-submodules add . and status'  '
      +	cd "${base_path}" &&
      +	cd main &&
     -+	GIT_TRACE=1 git add --force . &&
     ++	GIT_TRACE=1 git add --include-ignored-submodules . &&
      +	! git status --porcelain | grep "^M  sub$" &&
      +	echo
      +'
     @@ t/t2206-add-submodule-ignored.sh (new)
      +'
      +
      +#8
     -+# check that 'git add --force sub' does stage the change in the submodule
     -+# check that 'git add --force ./sub/' does stage the change in the submodule
     ++# check that 'git add --include-ignored-submodules sub' does stage the change in the submodule
     ++# check that 'git add --include-ignored-submodules ./sub/' does stage the change in the submodule
      +# and that 'git status --porcelain' does show it as modified
      +# commit it..
      +# check that 'git log --ignore-submodules=none' shows the submodule change
     @@ t/t2206-add-submodule-ignored.sh (new)
      +test_expect_success 'main: check force add sub and ./sub/ and status'  '
      +	cd "${base_path}" &&
      +	cd main &&
     -+	echo "Adding with --force should work: git add --force sub" &&
     -+	GIT_TRACE=1 git add --force sub &&
     ++	echo "Adding with --include-ignored-submodules should work: git add --include-ignored-submodules sub" &&
     ++	GIT_TRACE=1 git add --include-ignored-submodules sub &&
      +	git status --porcelain | grep "^M  sub$" &&
      +	git restore --staged sub &&
      +	! git status --porcelain | grep "^M  sub$" &&
     -+	echo "Adding with --force should work: git add --force ./sub/" &&
     -+	GIT_TRACE=1 git add --force ./sub/ &&
     ++	echo "Adding with --include-ignored-submodules should work: git add --include-ignored-submodules ./sub/" &&
     ++	GIT_TRACE=1 git add --include-ignored-submodules ./sub/ &&
      +	git status --porcelain | grep "^M  sub$" &&
      +	git commit -m "update submodule pointer" &&
      +	! git status --porcelain | grep "^ M sub$" &&
 4:  58563a7b90 ! 4:  93c95954f1 tests: fix existing tests when add an ignore=all submodule
     @@ Metadata
       ## Commit message ##
          tests: fix existing tests when add an ignore=all submodule
      
     -    There are tests that rely on "git add <submodule>" also adds it. A --force
     -    is needed with this enhancement hence they are added accordingly in these
     -    tests.
     +    There are tests that rely on "git add <submodule>" to add updates in the
     +    parent repository. A new option --include-ignored-submodules is introduced
     +    as it is now needed with this enhancement.
      
          Updated tests:
          - t1013-read-tree-submodule.sh ( fixed in: t/lib-submodule-update.sh )
     +    - t2013-checkout-submodule.sh ( fixed in: t/lib-submodule-update.sh )
          - t7406-submodule-update.sh
          - t7508-status.sh
      
     @@ t/lib-submodule-update.sh: create_lib_submodule_repo () {
       			git push origin modifications
       		) &&
      -		git add sub1 &&
     -+		git add --force sub1 &&
     ++		git add --include-ignored-submodules sub1 &&
       		git commit -m "Modify sub1" &&
       
       		git checkout -b add_nested_sub modify_sub1 &&
     @@ t/lib-submodule-update.sh: create_lib_submodule_repo () {
       		git -C sub1 submodule add --branch no_submodule ../submodule_update_sub2 sub2 &&
       		git -C sub1 commit -a -m "add a nested submodule" &&
      -		git add sub1 &&
     -+		git add --force sub1 &&
     ++		git add --include-ignored-submodules sub1 &&
       		git commit -a -m "update submodule, that updates a nested submodule" &&
       		git checkout -b modify_sub1_recursively &&
       		git -C sub1 checkout -b modify_sub1_recursively &&
     @@ t/lib-submodule-update.sh: create_lib_submodule_repo () {
       		git -C sub1 add sub2 &&
       		git -C sub1 commit -m "update nested sub" &&
      -		git add sub1 &&
     -+		git add --force sub1 &&
     ++		git add --include-ignored-submodules sub1 &&
       		git commit -m "update sub1, that updates nested sub" &&
       		git -C sub1 push origin modify_sub1_recursively &&
       		git -C sub1/sub2 push origin modify_sub1_recursively &&
     @@ t/t7508-status.sh: test_expect_success 'git commit will commit a staged but igno
       test_expect_success 'git commit --dry-run will show a staged but ignored submodule' '
       	git reset HEAD^ &&
      -	git add sm &&
     -+	git add --force sm &&
     ++	git add --include-ignored-submodules sm &&
       	cat >expect << EOF &&
       On branch main
       Your branch and '\''upstream'\'' have diverged,
 5:  416695f439 < -:  ---------- Documentation: update add --force and submodule ignore=all config
 -:  ---------- > 5:  ee84190cd8 Documentation: add --include_ignored_submodules + ignore=all config
-- 
gitgitgadget
Claus Schneider(Eficode) via GitGitGadget· Nov 13, 2025, 18:10 UTC · re: Claus Schneider via GitGitGadget · lore

[PATCH v2 1/5] read-cache: update add_files_to_cache take param include_ignored_submodules

From: "Claus Schneider(Eficode)" <claus.schneider@eficode.com>

The include_ignored_submodules parameter is added to the function add_files_to_cache for usage of explicit updating the index for the updated submodule using the explicit patchspec to the submodule.

Signed-off-by: Claus Schneider(Eficode) <claus.schneider@eficode.com>
---
 builtin/add.c      |  4 +++-
 builtin/checkout.c |  2 +-
 builtin/commit.c   |  2 +-
 read-cache-ll.h    |  2 +-
 read-cache.c       | 51 ++++++++++++++++++++++++++++++++++++++++++++--
 5 files changed, 55 insertions(+), 6 deletions(-)
Show changes to 5 files +55 −6

builtin/add.c, builtin/checkout.c, builtin/commit.c, read-cache-ll.h, read-cache.c

diff --git a/builtin/add.c b/builtin/add.c
index 0235854f80..6d11382f33 100644
--- a/builtin/add.c
+++ b/builtin/add.c
@@ -233,6 +233,7 @@ N_("The following paths are ignored by one of your .gitignore files:\n");
 static int verbose, show_only, ignored_too, refresh_only;
 static int ignore_add_errors, intent_to_add, ignore_missing;
 static int warn_on_embedded_repo = 1;
+static int include_ignored_submodules;
 
 #define ADDREMOVE_DEFAULT 1
 static int addremove = ADDREMOVE_DEFAULT;
@@ -271,6 +272,7 @@ static struct option builtin_add_options[] = {
 	OPT_BOOL( 0 , "ignore-errors", &ignore_add_errors, N_("just skip files which cannot be added because of errors")),
 	OPT_BOOL( 0 , "ignore-missing", &ignore_missing, N_("check if - even missing - files are ignored in dry run")),
 	OPT_BOOL(0, "sparse", &include_sparse, N_("allow updating entries outside of the sparse-checkout cone")),
+    OPT_BOOL(0, "include-ignored-submodules", &include_ignored_submodules, N_("add submodules even if they has configuration ignore=all")),
 	OPT_STRING(0, "chmod", &chmod_arg, "(+|-)x",
 		   N_("override the executable bit of the listed files")),
 	OPT_HIDDEN_BOOL(0, "warn-embedded-repo", &warn_on_embedded_repo,
@@ -582,7 +584,7 @@ int cmd_add(int argc,
 	else
 		exit_status |= add_files_to_cache(repo, prefix,
 						  &pathspec, ps_matched,
-						  include_sparse, flags);
+						  include_sparse, flags, include_ignored_submodules);
 
 	if (take_worktree_changes && !add_renormalize && !ignore_add_errors &&
 	    report_path_error(ps_matched, &pathspec))
diff --git a/builtin/checkout.c b/builtin/checkout.c
index f9453473fe..b2a404051d 100644
--- a/builtin/checkout.c
+++ b/builtin/checkout.c
@@ -899,7 +899,7 @@ static int merge_working_tree(const struct checkout_opts *opts,
 			 */
 
 			add_files_to_cache(the_repository, NULL, NULL, NULL, 0,
-					   0);
+					   0, 0 );
 			init_ui_merge_options(&o, the_repository);
 			o.verbosity = 0;
 			work = write_in_core_index_as_tree(the_repository);
diff --git a/builtin/commit.c b/builtin/commit.c
index b5b9608813..5bf7ae5fc1 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -455,7 +455,7 @@ static const char *prepare_index(const char **argv, const char *prefix,
 		repo_hold_locked_index(the_repository, &index_lock,
 				       LOCK_DIE_ON_ERROR);
 		add_files_to_cache(the_repository, also ? prefix : NULL,
-				   &pathspec, ps_matched, 0, 0);
+				   &pathspec, ps_matched, 0, 0, 0 );
 		if (!all && report_path_error(ps_matched, &pathspec))
 			exit(128);
 
diff --git a/read-cache-ll.h b/read-cache-ll.h
index 71b49d9af4..2c8b4b21b1 100644
--- a/read-cache-ll.h
+++ b/read-cache-ll.h
@@ -481,7 +481,7 @@ int cmp_cache_name_compare(const void *a_, const void *b_);
 
 int add_files_to_cache(struct repository *repo, const char *prefix,
 		       const struct pathspec *pathspec, char *ps_matched,
-		       int include_sparse, int flags);
+		       int include_sparse, int flags, int ignored_too );
 
 void overlay_tree_on_index(struct index_state *istate,
 			   const char *tree_name, const char *prefix);
diff --git a/read-cache.c b/read-cache.c
index 06ad74db22..32f32bdb4c 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -3880,9 +3880,12 @@ void overlay_tree_on_index(struct index_state *istate,
 
 struct update_callback_data {
 	struct index_state *index;
+	struct repository *repo;
+	struct pathspec *pathspec;
 	int include_sparse;
 	int flags;
 	int add_errors;
+	int include_ignored_submodules;
 };
 
 static int fix_unmerged_status(struct diff_filepair *p,
@@ -3924,7 +3927,48 @@ static void update_callback(struct diff_queue_struct *q,
 		default:
 			die(_("unexpected diff status %c"), p->status);
 		case DIFF_STATUS_MODIFIED:
-		case DIFF_STATUS_TYPE_CHANGED:
+		case DIFF_STATUS_TYPE_CHANGED: {
+			struct stat st;
+			if (!lstat(path, &st) && S_ISDIR(st.st_mode)) { // only consider submodule if it is a directory
+				const struct submodule *sub = submodule_from_path(data->repo, null_oid(the_hash_algo), path);
+				if (sub && sub->name && sub->ignore && !strcmp(sub->ignore, "all")) {
+					int pathspec_matches = 0;
+					char *norm_pathspec = NULL;
+					int ps_i;
+					trace_printf("ignore=all %s\n", path);
+					trace_printf("pathspec %s\n",
+							(data->pathspec && data->pathspec->nr) ? "has pathspec" : "no pathspec");
+					/* Safely scan all pathspec items (q->nr may exceed pathspec->nr). */
+					if (data->pathspec) {
+						for (ps_i = 0; ps_i < data->pathspec->nr; ps_i++) {
+							const char *m = data->pathspec->items[ps_i].match;
+							if (!m)
+								continue;
+							norm_pathspec = xstrdup(m);
+							strip_dir_trailing_slashes(norm_pathspec);
+							if (!strcmp(path, norm_pathspec)) {
+								pathspec_matches = 1;
+								FREE_AND_NULL(norm_pathspec);
+								break;
+							}
+							FREE_AND_NULL(norm_pathspec);
+						}
+					}
+					if (pathspec_matches) {
+						if (data->include_ignored_submodules && data->include_ignored_submodules > 0) {
+							trace_printf("Add ignored=all submodule due to --include_ignored_submodules: %s\n", path);
+						} else {
+							printf(_("Skipping submodule due to ignore=all: %s"), path);
+							printf(_("Use --include_ignored_submodules, if you really want to add them.") );
+							continue;
+						}
+					} else {
+						/* No explicit pathspec match -> skip silently (or with trace). */
+						trace_printf("pathspec does not match %s\n", path);
+						continue;
+					}
+				}
+			}
 			if (add_file_to_index(data->index, path, data->flags)) {
 				if (!(data->flags & ADD_CACHE_IGNORE_ERRORS))
 					die(_("updating files failed"));
@@ -3945,7 +3989,7 @@ static void update_callback(struct diff_queue_struct *q,
 
 int add_files_to_cache(struct repository *repo, const char *prefix,
 		       const struct pathspec *pathspec, char *ps_matched,
-		       int include_sparse, int flags)
+		       int include_sparse, int flags, int include_ignored_submodules )
 {
 	struct update_callback_data data;
 	struct rev_info rev;
@@ -3954,6 +3998,9 @@ int add_files_to_cache(struct repository *repo, const char *prefix,
 	data.index = repo->index;
 	data.include_sparse = include_sparse;
 	data.flags = flags;
+	data.repo = repo;
+	data.include_ignored_submodules = include_ignored_submodules;
+	data.pathspec = (struct pathspec *)pathspec;
 
 	repo_init_revisions(repo, &rev, prefix);
 	setup_revisions(0, NULL, &rev, NULL);
-- 
gitgitgadget
Claus Schneider(Eficode) via GitGitGadget· Nov 13, 2025, 18:10 UTC · re: Claus Schneider via GitGitGadget · lore

[PATCH v2 2/5] read-cache: add/read-cache respect submodule ignore=all

From: "Claus Schneider(Eficode)" <claus.schneider@eficode.com>

Submodules configured with ignore=all are now skipped during add operations unless overridden by --include-ignored-submodules and the submodule path is explicitly specified.

A message is printed (like ignored files) guiding the user to use the --include-ignored-submodules flag if the user has explicitely want to update the submodule reference.

The reason for the change is support submodule branch tracking or similar and git status state nothing and git add should not add either. The workflow is more logic and similar to regular ignored files even the submodule is already tracked.

The change opens up a lot of possibilities for submodules to be used more freely and simular to the repo tool. A submodule can be added for many more reason and loosely coupled dependencies to the super repo which often gives the friction of handle the explicit commits and updates without the need for tracking the submodule sha1 by sha1.

Signed-off-by: Claus Schneider(Eficode) <claus.schneider@eficode.com>
---
 read-cache.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
Show changes to read-cache.c +5 −2
diff --git a/read-cache.c b/read-cache.c
index 32f32bdb4c..7b6d1b2914 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -48,6 +48,8 @@
 #include "csum-file.h"
 #include "promisor-remote.h"
 #include "hook.h"
+#include "submodule.h"
+#include "submodule-config.h"
 
 /* Mask for the name length in ce_flags in the on-disk index */
 
@@ -3956,7 +3958,7 @@ static void update_callback(struct diff_queue_struct *q,
 					}
 					if (pathspec_matches) {
 						if (data->include_ignored_submodules && data->include_ignored_submodules > 0) {
-							trace_printf("Add ignored=all submodule due to --include_ignored_submodules: %s\n", path);
+							trace_printf("Add submodule due to --include_ignored_submodules: %s\n", path);
 						} else {
 							printf(_("Skipping submodule due to ignore=all: %s"), path);
 							printf(_("Use --include_ignored_submodules, if you really want to add them.") );
@@ -3964,7 +3966,7 @@ static void update_callback(struct diff_queue_struct *q,
 						}
 					} else {
 						/* No explicit pathspec match -> skip silently (or with trace). */
-						trace_printf("pathspec does not match %s\n", path);
+						trace_printf("Pathspec to submodule does not match explicitly: %s\n", path);
 						continue;
 					}
 				}
@@ -3975,6 +3977,7 @@ static void update_callback(struct diff_queue_struct *q,
 				data->add_errors++;
 			}
 			break;
+		}
 		case DIFF_STATUS_DELETED:
 			if (data->flags & ADD_CACHE_IGNORE_REMOVAL)
 				break;
-- 
gitgitgadget
Claus Schneider(Eficode) via GitGitGadget· Nov 13, 2025, 18:10 UTC · re: Claus Schneider via GitGitGadget · lore

[PATCH v2 3/5] tests: add new t2206-add-submodule-ignored.sh to test ignore=all scenario

From: "Claus Schneider(Eficode)" <claus.schneider@eficode.com>

The tests verify that the submodule behavior is intact and updating the config with ignore=all also behaves as intended with configuration in .gitmodules and configuration given on the command line.

The usage of --include_ignored_submodules is showcased and tested in the test suite.

The test file is added to meson.build for execution.
Signed-off-by: Claus Schneider(Eficode) <claus.schneider@eficode.com>
---
 t/meson.build                    |   1 +
 t/t2206-add-submodule-ignored.sh | 134 +++++++++++++++++++++++++++++++
 2 files changed, 135 insertions(+)
 create mode 100755 t/t2206-add-submodule-ignored.sh
Show changes to 2 files +135 −0

t/meson.build, t/t2206-add-submodule-ignored.sh

diff --git a/t/meson.build b/t/meson.build
index 983245501c..49e29ae82f 100644
--- a/t/meson.build
+++ b/t/meson.build
@@ -282,6 +282,7 @@ integration_tests = [
   't2203-add-intent.sh',
   't2204-add-ignored.sh',
   't2205-add-worktree-config.sh',
+  't2206-add-submodule-ignored.sh',
   't2300-cd-to-toplevel.sh',
   't2400-worktree-add.sh',
   't2401-worktree-prune.sh',
diff --git a/t/t2206-add-submodule-ignored.sh b/t/t2206-add-submodule-ignored.sh
new file mode 100755
index 0000000000..2c8a523641
--- /dev/null
+++ b/t/t2206-add-submodule-ignored.sh
@@ -0,0 +1,134 @@
+#!/bin/sh
+# shellcheck disable=SC2016
+
+# shellcheck disable=SC2034
+test_description='git add respects submodule ignore=all and explicit pathspec'
+
+# This test covers the behavior of "git add", "git status" and "git log" when
+# dealing with submodules that have the ignore=all setting in
+# .gitmodules. It ensures that changes in such submodules are
+# ignored by default, but can be staged with "git add --include-ignored-submodules".
+
+# shellcheck disable=SC1091
+. ./test-lib.sh
+
+GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
+export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
+
+base_path=$(pwd -P)
+
+#1
+test_expect_success 'setup: create origin repos'  '
+	cd "${base_path}" &&
+	git config --global protocol.file.allow always &&
+	git init sub &&
+		pwd &&
+		cd sub &&
+		test_commit sub_file1 &&
+		git tag v1.0 &&
+		test_commit sub_file2 &&
+		git tag v2.0 &&
+		test_commit sub_file3 &&
+		git tag v3.0 &&
+	cd "${base_path}" &&
+	git init main &&
+		cd main &&
+		test_commit first &&
+	cd "${base_path}"
+'
+#2
+# add submodule with default config (ignore=none) and
+# check log that is contains a path entry for the submodule 'sub'
+# change the commit in the submodule and check that 'git status' shows it as modified
+test_expect_success 'main: add submodule with default config'  '
+	cd "${base_path}" &&
+	cd main &&
+	git submodule add ../sub &&
+	git commit -m "add submodule" &&
+	git log --oneline --name-only | grep "^sub$" &&
+	git -C sub reset --hard v2.0 &&
+	git status --porcelain | grep "^ M sub$" &&
+	echo
+'
+#3
+# change the submodule config to ignore=all and check that status and log do not show changes
+test_expect_success 'main: submodule config ignore=all'  '
+	cd "${base_path}" &&
+	cd main &&
+	git config -f .gitmodules submodule.sub.ignore all &&
+	GIT_TRACE=1 git add . &&
+	git commit -m "update submodule config sub.ignore all" &&
+	! git status --porcelain | grep "^.*$" &&
+	! git log --oneline --name-only | grep "^sub$" &&
+	echo
+'
+#4
+# change the commit in the submodule and check that 'git status' does not show it as modified
+# but 'git status --ignore-submodules=none' does show it as modified
+test_expect_success 'sub: change to different sha1 and check status in main'  '
+	cd "${base_path}" &&
+	cd main &&
+	git -C sub reset --hard v1.0 &&
+	! git status --porcelain | grep "^ M sub$" &&
+	git status --ignore-submodules=none --porcelain | grep "^ M sub$" &&
+	echo
+'
+
+#5
+# check that normal 'git add' does not stage the change in the submodule
+test_expect_success 'main: check normal add and status'  '
+	cd "${base_path}" &&
+	cd main &&
+	GIT_TRACE=1 git add . &&
+	! git status --porcelain | grep "^ M sub$" &&
+	echo
+'
+
+#6
+# check that 'git add --include-ignored-submodules .' does not stage the change in the submodule
+# and that 'git status' does not show it as modified
+test_expect_success 'main: check --include-ignored-submodules add . and status'  '
+	cd "${base_path}" &&
+	cd main &&
+	GIT_TRACE=1 git add --include-ignored-submodules . &&
+	! git status --porcelain | grep "^M  sub$" &&
+	echo
+'
+
+#7
+# check that 'git add .' does not stage the change in the submodule
+# and that 'git status' does not show it as modified
+test_expect_success 'main: check _add sub_ and status'  '
+	cd "${base_path}" &&
+	cd main &&
+	GIT_TRACE=1 git add sub | grep "Skipping submodule due to ignore=all: sub" &&
+	! git status --porcelain | grep "^M  sub$" &&
+	echo
+'
+
+#8
+# check that 'git add --include-ignored-submodules sub' does stage the change in the submodule
+# check that 'git add --include-ignored-submodules ./sub/' does stage the change in the submodule
+# and that 'git status --porcelain' does show it as modified
+# commit it..
+# check that 'git log --ignore-submodules=none' shows the submodule change
+# in the log
+test_expect_success 'main: check force add sub and ./sub/ and status'  '
+	cd "${base_path}" &&
+	cd main &&
+	echo "Adding with --include-ignored-submodules should work: git add --include-ignored-submodules sub" &&
+	GIT_TRACE=1 git add --include-ignored-submodules sub &&
+	git status --porcelain | grep "^M  sub$" &&
+	git restore --staged sub &&
+	! git status --porcelain | grep "^M  sub$" &&
+	echo "Adding with --include-ignored-submodules should work: git add --include-ignored-submodules ./sub/" &&
+	GIT_TRACE=1 git add --include-ignored-submodules ./sub/ &&
+	git status --porcelain | grep "^M  sub$" &&
+	git commit -m "update submodule pointer" &&
+	! git status --porcelain | grep "^ M sub$" &&
+	git log --ignore-submodules=none --name-only --oneline | grep "^sub$" &&
+	echo
+'
+
+test_done
+exit 0
-- 
gitgitgadget
Claus Schneider(Eficode) via GitGitGadget· Nov 13, 2025, 18:10 UTC · re: Claus Schneider via GitGitGadget · lore

[PATCH v2 4/5] tests: fix existing tests when add an ignore=all submodule

From: "Claus Schneider(Eficode)" <claus.schneider@eficode.com>

There are tests that rely on "git add <submodule>" to add updates in the parent repository. A new option --include-ignored-submodules is introduced as it is now needed with this enhancement.

Updated tests:
- t1013-read-tree-submodule.sh ( fixed in: t/lib-submodule-update.sh )
- t2013-checkout-submodule.sh ( fixed in: t/lib-submodule-update.sh )
- t7406-submodule-update.sh
- t7508-status.sh
Signed-off-by: Claus Schneider(Eficode) <claus.schneider@eficode.com>
---
 t/lib-submodule-update.sh | 6 +++---
 t/t7508-status.sh         | 2 +-
 2 files changed, 4 insertions(+), 4 deletions(-)
Show changes to 2 files +4 −4

t/lib-submodule-update.sh, t/t7508-status.sh

diff --git a/t/lib-submodule-update.sh b/t/lib-submodule-update.sh
index 36f767cb74..fde5dbee02 100644
--- a/t/lib-submodule-update.sh
+++ b/t/lib-submodule-update.sh
@@ -95,14 +95,14 @@ create_lib_submodule_repo () {
 			git commit -m "modified file2 and added file3" &&
 			git push origin modifications
 		) &&
-		git add sub1 &&
+		git add --include-ignored-submodules sub1 &&
 		git commit -m "Modify sub1" &&
 
 		git checkout -b add_nested_sub modify_sub1 &&
 		git -C sub1 checkout -b "add_nested_sub" &&
 		git -C sub1 submodule add --branch no_submodule ../submodule_update_sub2 sub2 &&
 		git -C sub1 commit -a -m "add a nested submodule" &&
-		git add sub1 &&
+		git add --include-ignored-submodules sub1 &&
 		git commit -a -m "update submodule, that updates a nested submodule" &&
 		git checkout -b modify_sub1_recursively &&
 		git -C sub1 checkout -b modify_sub1_recursively &&
@@ -112,7 +112,7 @@ create_lib_submodule_repo () {
 		git -C sub1/sub2 commit -m "make a change in nested sub" &&
 		git -C sub1 add sub2 &&
 		git -C sub1 commit -m "update nested sub" &&
-		git add sub1 &&
+		git add --include-ignored-submodules sub1 &&
 		git commit -m "update sub1, that updates nested sub" &&
 		git -C sub1 push origin modify_sub1_recursively &&
 		git -C sub1/sub2 push origin modify_sub1_recursively &&
diff --git a/t/t7508-status.sh b/t/t7508-status.sh
index cdc1d6fcc7..5c8ffed21b 100755
--- a/t/t7508-status.sh
+++ b/t/t7508-status.sh
@@ -1565,7 +1565,7 @@ test_expect_success 'git commit will commit a staged but ignored submodule' '
 
 test_expect_success 'git commit --dry-run will show a staged but ignored submodule' '
 	git reset HEAD^ &&
-	git add sm &&
+	git add --include-ignored-submodules sm &&
 	cat >expect << EOF &&
 On branch main
 Your branch and '\''upstream'\'' have diverged,
-- 
gitgitgadget
Claus Schneider(Eficode) via GitGitGadget· Nov 13, 2025, 18:10 UTC · re: Claus Schneider via GitGitGadget · lore

[PATCH v2 5/5] Documentation: add --include_ignored_submodules + ignore=all config

From: "Claus Schneider(Eficode)" <claus.schneider@eficode.com>
- git-add.adoc: Add new documentation for --include_ignored_submodules
  option to supress ignore=all and new submodule functionality of not
  adding a ignore=all submodule by default.
- gitmodules.adoc and config/submodule.adoc: The submodule config
  ignore=all now need --include_ignored_submodules in order to update
  the index.
Signed-off-by: Claus Schneider(Eficode) <claus.schneider@eficode.com>
---
 .devcontainer/Dockerfile            | 70 ++++++++++++++++++++++++++
 .devcontainer/Dockerfile.standalone | 76 +++++++++++++++++++++++++++++
 .devcontainer/devcontainer.json     | 25 ++++++++++
 Documentation/config/submodule.adoc | 13 ++---
 Documentation/git-add.adoc          |  5 ++
 Documentation/gitmodules.adoc       |  5 +-
 6 files changed, 187 insertions(+), 7 deletions(-)
 create mode 100644 .devcontainer/Dockerfile
 create mode 100644 .devcontainer/Dockerfile.standalone
 create mode 100644 .devcontainer/devcontainer.json
Show changes to 6 files +187 −7

.devcontainer/Dockerfile, .devcontainer/Dockerfile.standalone, .devcontainer/devcontainer.json, Documentation/config/submodule.adoc, Documentation/git-add.adoc, Documentation/gitmodules.adoc

diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile
new file mode 100644
index 0000000000..680ca5f3ad
--- /dev/null
+++ b/.devcontainer/Dockerfile
@@ -0,0 +1,70 @@
+FROM ubuntu:latest
+
+ARG USER_ID
+ARG GROUP_ID
+
+ENV DEBIAN_FRONTEND=noninteractive
+ENV TZ=Europe/Copenhagen
+
+RUN apt-get update \
+    && \
+    apt-get install -y \
+        sudo \
+        build-essential \
+        libcurl4-gnutls-dev \
+        libexpat1-dev \
+        gettext \
+        libz-dev \
+        libssl-dev \
+        asciidoc \
+        xmlto \
+        docbook-xsl \
+        \
+        tzdata \
+        git \
+        coccinelle \
+    && \
+    ln -fs /usr/share/zoneinfo/$TZ /etc/localtime \
+    && \
+    dpkg-reconfigure --frontend noninteractive tzdata
+
+RUN  apt-get update && apt-get install -y autoconf
+
+RUN addgroup -gid 1001 gituser
+RUN adduser --disabled-password -u 1001 -gid 1001 gituser
+RUN usermod -aG sudo gituser
+RUN echo 'gituser ALL=(ALL) NOPASSWD:ALL' > /etc/sudoers.d/010-gituser
+RUN chmod 0440 /etc/sudoers.d/010-gituser
+
+USER 1001
+
+#WORKDIR /home/gituser/git-src/
+
+#RUN  make configure
+#RUN ./configure --prefix=${HOME}/.local/
+
+#RUN make -j$(nproc) gitweb || make gitweb 
+#RUN make install-gitweb
+
+#RUN make -j$(nproc) || make
+#RUN make -j$(nproc) gitweb || make gitweb 
+#RUN make install-gitweb
+#RUN make -j$(nproc) NO_PERL=YesPlease install || make NO_PERL=YesPlease install
+#RUN make install
+
+
+RUN mkdir -p  ${HOME}/.local/
+#RUN ls -la ${HOME}/.local/bin
+#ENV PATH="/home/gituser/.local/bin:${PATH}"
+#RUN ls -l $HOME/.local/bin
+#RUN echo $PATH $HOME 
+
+#RUN git --version
+#RUN which git 
+
+RUN git config --global user.email "gituser@example.com"
+RUN git config --global user.name "Git User"
+
+#WORKDIR /home/gituser/git-test/
+
+#CMD [ "git" ]
diff --git a/.devcontainer/Dockerfile.standalone b/.devcontainer/Dockerfile.standalone
new file mode 100644
index 0000000000..39bda42c0e
--- /dev/null
+++ b/.devcontainer/Dockerfile.standalone
@@ -0,0 +1,76 @@
+FROM ubuntu:latest
+
+ARG USER_ID
+ARG GROUP_ID
+
+ENV DEBIAN_FRONTEND=noninteractive
+ENV TZ=Europe/Copenhagen
+
+RUN apt-get update \
+    && \
+    apt-get install -y \
+        build-essential \
+        libcurl4-gnutls-dev \
+        libexpat1-dev \
+        gettext \
+        libz-dev \
+        libssl-dev \
+        asciidoc \
+        xmlto \
+        docbook-xsl \
+        \
+        tzdata \
+        \
+        nano \
+        vim \
+    && \
+    ln -fs /usr/share/zoneinfo/$TZ /etc/localtime \
+    && \
+    dpkg-reconfigure --frontend noninteractive tzdata
+
+RUN  apt-get update && apt-get install -y autoconf
+
+RUN addgroup -gid ${GROUP_ID} gituser
+RUN adduser --disabled-password -u ${USER_ID} -gid ${GROUP_ID} gituser
+
+
+COPY --chown=${USER_ID}:${GROUP_ID} ./git /home/gituser/git-src/
+
+USER ${USER_ID}
+
+WORKDIR /home/gituser/git-src/
+
+RUN  make configure
+RUN ./configure --prefix=${HOME}/.local/
+
+#RUN make -j$(nproc) gitweb || make gitweb 
+#RUN make install-gitweb
+
+#RUN make -j$(nproc) || make
+#RUN make -j$(nproc) gitweb || make gitweb 
+#RUN make install-gitweb
+RUN make -j$(nproc) NO_PERL=YesPlease install || make NO_PERL=YesPlease install
+RUN make install
+
+WORKDIR /home/gituser/git-src/t
+RUN ./t2206-add-submodule-ignored.sh -v
+
+RUN ls -la ${HOME}/.local/
+RUN ls -la ${HOME}/.local/bin
+ENV PATH="/home/gituser/.local/bin:${PATH}"
+RUN ls -l $HOME/.local/bin
+RUN echo $PATH $HOME 
+
+RUN git --version
+RUN which git 
+
+RUN git config --global user.email "gituser@example.com"
+RUN git config --global user.name "Git User"
+
+WORKDIR /home/gituser/git-src/t
+RUN pwd && ls -la 
+RUN ./t2206-add-submodule-ignored.sh -v
+
+WORKDIR /home/gituser/git-test/
+
+CMD [ "git" ]
diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json
new file mode 100644
index 0000000000..2bc13902d8
--- /dev/null
+++ b/.devcontainer/devcontainer.json
@@ -0,0 +1,25 @@
+{
+  "name": "Git Dev Container",
+  "build": {
+    "dockerfile": "Dockerfile",
+    "context": "",
+    "args": {
+      "user_id": "1001",
+      "group_id": "1001"
+    }
+  },
+  "customizations": {
+    "vscode": {
+      "settings": {
+        "terminal.integrated.shell.linux": "/bin/bash"
+      }
+    }
+  },
+  "remoteUser": "gituser",
+  "features": {},
+  "mounts": [
+    "source=${localWorkspaceFolder}/,target=/home/gitusers/git-src,type=bind,consistency=cached",
+    "source=${localWorkspaceFolder}/,target=/home/gitusers/git-test,type=bind,consistency=cached"
+  ],
+  "postCreateCommand": "echo"
+}
diff --git a/Documentation/config/submodule.adoc b/Documentation/config/submodule.adoc
index 0672d99117..0753adbab5 100644
--- a/Documentation/config/submodule.adoc
+++ b/Documentation/config/submodule.adoc
@@ -32,15 +32,16 @@ submodule.<name>.fetchRecurseSubmodules::
 
 submodule.<name>.ignore::
 	Defines under what circumstances "git status" and the diff family show
-	a submodule as modified. When set to "all", it will never be considered
-	modified (but it will nonetheless show up in the output of status and
-	commit when it has been staged), "dirty" will ignore all changes
-	to the submodule's work tree and
+	a submodule as modified.
+	Set to "all" will never considered the submodule modified. It can
+	nevertheless be staged using the option --include_ignored_submodules and
+	it will then show up in the output of status.
+	Set to "dirty" will ignore all changes to the submodule's work tree and
 	takes only differences between the HEAD of the submodule and the commit
 	recorded in the superproject into account. "untracked" will additionally
 	let submodules with modified tracked files in their work tree show up.
-	Using "none" (the default when this option is not set) also shows
-	submodules that have untracked files in their work tree as changed.
+	Set to "none"(default) It is also shows submodules that have untracked
+	files in their work tree as changed.
 	This setting overrides any setting made in .gitmodules for this submodule,
 	both settings can be overridden on the command line by using the
 	"--ignore-submodules" option. The 'git submodule' commands are not
diff --git a/Documentation/git-add.adoc b/Documentation/git-add.adoc
index b7a735824d..ab72fad651 100644
--- a/Documentation/git-add.adoc
+++ b/Documentation/git-add.adoc
@@ -79,6 +79,11 @@ in linkgit:gitglossary[7].
 `--force`::
 	Allow adding otherwise ignored files.
 
+`--include_ignored_submodules`::
+	The option is also used when `submodule.<name>.ignore=all`
+	is set, but you want to stage an update of the submodule. The
+	`path` to the submodule must be explicitly specified.
+
 `--sparse`::
 	Allow updating index entries outside of the sparse-checkout cone.
 	Normally, `git add` refuses to update index entries whose paths do
diff --git a/Documentation/gitmodules.adoc b/Documentation/gitmodules.adoc
index d9bec8b187..ea1fd377e6 100644
--- a/Documentation/gitmodules.adoc
+++ b/Documentation/gitmodules.adoc
@@ -70,7 +70,10 @@ submodule.<name>.ignore::
 --
 	all;; The submodule will never be considered modified (but will
 	    nonetheless show up in the output of status and commit when it has
-	    been staged).
+	    been staged). Add `(new commits)` can be overruled using the
+	    `git add --include_ignored_submodules <submodule.path>` 
+		The setting affects `status`, `update-index`, `diff` and `log`(due 
+		to underlaying `diff`).
 
 	dirty;; All changes to the submodule's work tree will be ignored, only
 	    committed differences between the `HEAD` of the submodule and its
-- 
gitgitgadget
Junio C Hamano· Nov 13, 2025, 19:58 UTC · re: Claus Schneider via GitGitGadget · lore

Re: [PATCH v2 0/5] git-add : Respect submodule ignore=all and only add changes with --force

"Claus Schneider via GitGitGadget" <gitgitgadget@gmail.com> writes:
> The feature of configuring a submodule to "ignore=all" is nicely respected
> in commands "status" and "diff".

"nicely respected" is not very informative for those who do not know what the setting does. Saying something like

    "git status" and "git diff" will not report modified submodules
    with submodule.<name>.ignore set to "all".

would not waste significantly more bytes than what you wrote, and is more helpful.

> However the "add" command does not respect
> the configuration the same way.

Again, "does not respect" and then what? Running "git add" on a submodule with submodule.<name>.ignore set to "all" does what? Complains that it has changes but because .ignore is set it won't add? Adds it silently? Something else?

> The behavior is problematic for the logic
> between status/diff and add.

After this sentence, "because ..." is missing. Please help readers understand the issue you perceive as problematic more easily.

I am guessing that you are assuming that an "add", after "diff" or "status" said there is no change, is expected to be a no-op, but I cannot be sure if that is what you are referring to here with the reason left unsaid like the above.

Show 10 quoted lines
> Secondly it makes it problematic to track
> branches in the submodule configuration as developers unintentionally keeps
> add submodule updates and get conflicts for no intentional reason. Both adds
> unnecessary friction to the usage of submodules.
>
> The patches implement the same logical behavior for ignore=all submodules as
> regular ignored files. The status now does not show any diff - nor will the
> add command update the reference submodule reference. If you add the
> submodule path which is ignore=all then you are presented with a message
> that you need to use the --force option.

I vaguely recall that an earlier discussion between you and Phillip were concluding against "--force"? I personally feel it is in line with "git add foo.o" (when '*.o' is in .gitignore) gets rejected and "git add -f foo.o" is a way to override it, but in the list of patches below, I see --include-ignored-submodules (no, our command line option names do not use underscore for inter-word-gaps), so I suspect the description in the cover letter around here is stale?

> The branch=, ignore=all (and
> update=none) now works great with update --remote,

Again, "great" is not very informative, and as bad as "nicely respected". Avoid using these adjectives loaded with unnecessary value judgements, and instead trust your readers. They are intelligent to judge if the updated behaviour is great or not for themselves. Try to use the same bytes on helping readers understand what actually happens.

> but developers does not
"do not".
Show 397 quoted lines
> have to consider changes in the updates of the submodule sha1. The
> implementation removes a friction of working with submodules and can be used
> like the repo tool with branches configured. The submodule status report
> could be used for build/release documentation for reproduction of a setup.
>
> A few tests used the adding of submodules without --force, hence they have
> been updated to use the --force option.
>
> Claus Schneider(Eficode) (5):
>   read-cache: update add_files_to_cache take param
>     include_ignored_submodules
>   read-cache: add/read-cache respect submodule ignore=all
>   tests: add new t2206-add-submodule-ignored.sh to test ignore=all
>     scenario
>   tests: fix existing tests when add an ignore=all submodule
>   Documentation: add --include_ignored_submodules + ignore=all config
>
>  .devcontainer/Dockerfile            |  70 +++++++++++++++
>  .devcontainer/Dockerfile.standalone |  76 ++++++++++++++++
>  .devcontainer/devcontainer.json     |  25 ++++++
>  Documentation/config/submodule.adoc |  13 +--
>  Documentation/git-add.adoc          |   5 ++
>  Documentation/gitmodules.adoc       |   5 +-
>  builtin/add.c                       |   4 +-
>  builtin/checkout.c                  |   2 +-
>  builtin/commit.c                    |   2 +-
>  read-cache-ll.h                     |   2 +-
>  read-cache.c                        |  54 ++++++++++-
>  t/lib-submodule-update.sh           |   6 +-
>  t/meson.build                       |   1 +
>  t/t2206-add-submodule-ignored.sh    | 134 ++++++++++++++++++++++++++++
>  t/t7508-status.sh                   |   2 +-
>  15 files changed, 384 insertions(+), 17 deletions(-)
>  create mode 100644 .devcontainer/Dockerfile
>  create mode 100644 .devcontainer/Dockerfile.standalone
>  create mode 100644 .devcontainer/devcontainer.json
>  create mode 100755 t/t2206-add-submodule-ignored.sh
>
>
> base-commit: 81f86aacc4eb74cdb9c2c8082d36d2070c666045
> Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-1987%2FPraqma%2Frespect-submodule-ignore-v2
> Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-1987/Praqma/respect-submodule-ignore-v2
> Pull-Request: https://github.com/gitgitgadget/git/pull/1987
>
> Range-diff vs v1:
>
>  1:  d98cca698d ! 1:  5796009122 read-cache: update add_files_to_cache to take param ignored_too(--force)
>      @@ Metadata
>       Author: Claus Schneider(Eficode) <claus.schneider@eficode.com>
>       
>        ## Commit message ##
>      -    read-cache: update add_files_to_cache to take param ignored_too(--force)
>      +    read-cache: update add_files_to_cache take param include_ignored_submodules
>       
>      -    The ignored_too parameter is added to the function add_files_to_cache for
>      -    usage of explicit updating the index for the updated submodule using the
>      -    explicit patchspec to the submodule.
>      +    The include_ignored_submodules parameter is added to the function
>      +    add_files_to_cache for usage of explicit updating the index for the updated
>      +    submodule using the explicit patchspec to the submodule.
>       
>           Signed-off-by: Claus Schneider(Eficode) <claus.schneider@eficode.com>
>       
>        ## builtin/add.c ##
>      +@@ builtin/add.c: N_("The following paths are ignored by one of your .gitignore files:\n");
>      + static int verbose, show_only, ignored_too, refresh_only;
>      + static int ignore_add_errors, intent_to_add, ignore_missing;
>      + static int warn_on_embedded_repo = 1;
>      ++static int include_ignored_submodules;
>      + 
>      + #define ADDREMOVE_DEFAULT 1
>      + static int addremove = ADDREMOVE_DEFAULT;
>      +@@ builtin/add.c: static struct option builtin_add_options[] = {
>      + 	OPT_BOOL( 0 , "ignore-errors", &ignore_add_errors, N_("just skip files which cannot be added because of errors")),
>      + 	OPT_BOOL( 0 , "ignore-missing", &ignore_missing, N_("check if - even missing - files are ignored in dry run")),
>      + 	OPT_BOOL(0, "sparse", &include_sparse, N_("allow updating entries outside of the sparse-checkout cone")),
>      ++    OPT_BOOL(0, "include-ignored-submodules", &include_ignored_submodules, N_("add submodules even if they has configuration ignore=all")),
>      + 	OPT_STRING(0, "chmod", &chmod_arg, "(+|-)x",
>      + 		   N_("override the executable bit of the listed files")),
>      + 	OPT_HIDDEN_BOOL(0, "warn-embedded-repo", &warn_on_embedded_repo,
>       @@ builtin/add.c: int cmd_add(int argc,
>        	else
>        		exit_status |= add_files_to_cache(repo, prefix,
>        						  &pathspec, ps_matched,
>       -						  include_sparse, flags);
>      -+						  include_sparse, flags, ignored_too);
>      ++						  include_sparse, flags, include_ignored_submodules);
>        
>        	if (take_worktree_changes && !add_renormalize && !ignore_add_errors &&
>        	    report_path_error(ps_matched, &pathspec))
>      @@ read-cache.c: void overlay_tree_on_index(struct index_state *istate,
>        	int include_sparse;
>        	int flags;
>        	int add_errors;
>      -+	int ignored_too;
>      ++	int include_ignored_submodules;
>        };
>        
>        static int fix_unmerged_status(struct diff_filepair *p,
>       @@ read-cache.c: static void update_callback(struct diff_queue_struct *q,
>      + 		default:
>      + 			die(_("unexpected diff status %c"), p->status);
>      + 		case DIFF_STATUS_MODIFIED:
>      +-		case DIFF_STATUS_TYPE_CHANGED:
>      ++		case DIFF_STATUS_TYPE_CHANGED: {
>      ++			struct stat st;
>      ++			if (!lstat(path, &st) && S_ISDIR(st.st_mode)) { // only consider submodule if it is a directory
>      ++				const struct submodule *sub = submodule_from_path(data->repo, null_oid(the_hash_algo), path);
>      ++				if (sub && sub->name && sub->ignore && !strcmp(sub->ignore, "all")) {
>      ++					int pathspec_matches = 0;
>      ++					char *norm_pathspec = NULL;
>      ++					int ps_i;
>      ++					trace_printf("ignore=all %s\n", path);
>      ++					trace_printf("pathspec %s\n",
>      ++							(data->pathspec && data->pathspec->nr) ? "has pathspec" : "no pathspec");
>      ++					/* Safely scan all pathspec items (q->nr may exceed pathspec->nr). */
>      ++					if (data->pathspec) {
>      ++						for (ps_i = 0; ps_i < data->pathspec->nr; ps_i++) {
>      ++							const char *m = data->pathspec->items[ps_i].match;
>      ++							if (!m)
>      ++								continue;
>      ++							norm_pathspec = xstrdup(m);
>      ++							strip_dir_trailing_slashes(norm_pathspec);
>      ++							if (!strcmp(path, norm_pathspec)) {
>      ++								pathspec_matches = 1;
>      ++								FREE_AND_NULL(norm_pathspec);
>      ++								break;
>      ++							}
>      ++							FREE_AND_NULL(norm_pathspec);
>      ++						}
>      ++					}
>      ++					if (pathspec_matches) {
>      ++						if (data->include_ignored_submodules && data->include_ignored_submodules > 0) {
>      ++							trace_printf("Add ignored=all submodule due to --include_ignored_submodules: %s\n", path);
>      ++						} else {
>      ++							printf(_("Skipping submodule due to ignore=all: %s"), path);
>      ++							printf(_("Use --include_ignored_submodules, if you really want to add them.") );
>      ++							continue;
>      ++						}
>      ++					} else {
>      ++						/* No explicit pathspec match -> skip silently (or with trace). */
>      ++						trace_printf("pathspec does not match %s\n", path);
>      ++						continue;
>      ++					}
>      ++				}
>      ++			}
>      + 			if (add_file_to_index(data->index, path, data->flags)) {
>      + 				if (!(data->flags & ADD_CACHE_IGNORE_ERRORS))
>      + 					die(_("updating files failed"));
>      +@@ read-cache.c: static void update_callback(struct diff_queue_struct *q,
>        
>        int add_files_to_cache(struct repository *repo, const char *prefix,
>        		       const struct pathspec *pathspec, char *ps_matched,
>       -		       int include_sparse, int flags)
>      -+		       int include_sparse, int flags, int ignored_too )
>      ++		       int include_sparse, int flags, int include_ignored_submodules )
>        {
>        	struct update_callback_data data;
>        	struct rev_info rev;
>      @@ read-cache.c: int add_files_to_cache(struct repository *repo, const char *prefix
>        	data.include_sparse = include_sparse;
>        	data.flags = flags;
>       +	data.repo = repo;
>      -+	data.ignored_too = ignored_too;
>      ++	data.include_ignored_submodules = include_ignored_submodules;
>       +	data.pathspec = (struct pathspec *)pathspec;
>        
>        	repo_init_revisions(repo, &rev, prefix);
>  2:  d1b02617e6 ! 2:  9ec79b9a11 read-cache: let read-cache respect submodule ignore=all and --force
>      @@ Metadata
>       Author: Claus Schneider(Eficode) <claus.schneider@eficode.com>
>       
>        ## Commit message ##
>      -    read-cache: let read-cache respect submodule ignore=all and --force
>      +    read-cache: add/read-cache respect submodule ignore=all
>       
>      -    Given the submdule configuration is ignore=all then only update the
>      -    submdule if the --force option is given and the submodule is explicit
>      -    given in the pathspec.
>      +    Submodules configured with ignore=all are now skipped during add operations
>      +    unless overridden by --include-ignored-submodules and the submodule path is
>      +    explicitly specified.
>       
>           A message is printed (like ignored files) guiding the user to use the
>      -    --force flag if the user has explicitely want to update the submodule
>      -    reference.
>      +    --include-ignored-submodules flag if the user has explicitely want to update
>      +    the submodule reference.
>       
>           The reason for the change is support submodule branch tracking or
>           similar and git status state nothing and git add should not add either.
>      @@ Commit message
>           the submodule is already tracked.
>       
>           The change opens up a lot of possibilities for submodules to be used
>      -    more freely and a like the repo tool. A submodule can be added for many
>      +    more freely and simular to the repo tool. A submodule can be added for many
>           more reason and loosely coupled dependencies to the super repo which often
>           gives the friction of handle the explicit commits and updates without
>           the need for tracking the submodule sha1 by sha1.
>      @@ read-cache.c
>        /* Mask for the name length in ce_flags in the on-disk index */
>        
>       @@ read-cache.c: static void update_callback(struct diff_queue_struct *q,
>      - 		default:
>      - 			die(_("unexpected diff status %c"), p->status);
>      - 		case DIFF_STATUS_MODIFIED:
>      --		case DIFF_STATUS_TYPE_CHANGED:
>      -+		case DIFF_STATUS_TYPE_CHANGED: {
>      -+			struct stat st;
>      -+			if (!lstat(path, &st) && S_ISDIR(st.st_mode)) { // only consider submodule if it is a directory
>      -+				const struct submodule *sub = submodule_from_path(data->repo, null_oid(the_hash_algo), path);
>      -+				if (sub && sub->name && sub->ignore && !strcmp(sub->ignore, "all")) {
>      -+					int pathspec_matches = 0;
>      -+					char *norm_pathspec = NULL;
>      -+					int ps_i;
>      -+					trace_printf("ignore=all %s\n", path);
>      -+					trace_printf("pathspec %s\n",
>      -+							(data->pathspec && data->pathspec->nr) ? "has pathspec" : "no pathspec");
>      -+					/* Safely scan all pathspec items (q->nr may exceed pathspec->nr). */
>      -+					if (data->pathspec) {
>      -+						for (ps_i = 0; ps_i < data->pathspec->nr; ps_i++) {
>      -+							const char *m = data->pathspec->items[ps_i].match;
>      -+							if (!m)
>      -+								continue;
>      -+							norm_pathspec = xstrdup(m);
>      -+							strip_dir_trailing_slashes(norm_pathspec);
>      -+							if (!strcmp(path, norm_pathspec)) {
>      -+								pathspec_matches = 1;
>      -+								FREE_AND_NULL(norm_pathspec);
>      -+								break;
>      -+							}
>      -+							FREE_AND_NULL(norm_pathspec);
>      -+						}
>      -+					}
>      -+					if (pathspec_matches) {
>      -+						if (data->ignored_too && data->ignored_too > 0) {
>      -+							trace_printf("Forcing add of submodule ignored=all due to --force: %s\n", path);
>      -+						} else {
>      -+							printf(_("Skipping submodule due to ignore=all: %s"), path);
>      -+							printf(_("Use -f if you really want to add them.") );
>      -+							continue;
>      -+						}
>      -+					} else {
>      -+						/* No explicit pathspec match -> skip silently (or with trace). */
>      -+						trace_printf("pathspec does not match %s\n", path);
>      -+						continue;
>      -+					}
>      -+				}
>      -+			}
>      - 			if (add_file_to_index(data->index, path, data->flags)) {
>      - 				if (!(data->flags & ADD_CACHE_IGNORE_ERRORS))
>      - 					die(_("updating files failed"));
>      + 					}
>      + 					if (pathspec_matches) {
>      + 						if (data->include_ignored_submodules && data->include_ignored_submodules > 0) {
>      +-							trace_printf("Add ignored=all submodule due to --include_ignored_submodules: %s\n", path);
>      ++							trace_printf("Add submodule due to --include_ignored_submodules: %s\n", path);
>      + 						} else {
>      + 							printf(_("Skipping submodule due to ignore=all: %s"), path);
>      + 							printf(_("Use --include_ignored_submodules, if you really want to add them.") );
>      +@@ read-cache.c: static void update_callback(struct diff_queue_struct *q,
>      + 						}
>      + 					} else {
>      + 						/* No explicit pathspec match -> skip silently (or with trace). */
>      +-						trace_printf("pathspec does not match %s\n", path);
>      ++						trace_printf("Pathspec to submodule does not match explicitly: %s\n", path);
>      + 						continue;
>      + 					}
>      + 				}
>      +@@ read-cache.c: static void update_callback(struct diff_queue_struct *q,
>        				data->add_errors++;
>        			}
>        			break;
>  3:  8f3d5f7ec1 ! 3:  399a153b95 tests: add new t2206-add-submodule-ignored.sh to test ignore=all scenario
>      @@ Commit message
>           config with ignore=all also behaves as intended with configuration in
>           .gitmodules and configuration given on the command line.
>       
>      -    Testfile is added to meson.build for execution.
>      +    The usage of --include_ignored_submodules is showcased and tested in the
>      +    test suite.
>      +
>      +    The test file is added to meson.build for execution.
>       
>           Signed-off-by: Claus Schneider(Eficode) <claus.schneider@eficode.com>
>       
>      @@ t/t2206-add-submodule-ignored.sh (new)
>       +# This test covers the behavior of "git add", "git status" and "git log" when
>       +# dealing with submodules that have the ignore=all setting in
>       +# .gitmodules. It ensures that changes in such submodules are
>      -+# ignored by default, but can be staged with "git add --force".
>      ++# ignored by default, but can be staged with "git add --include-ignored-submodules".
>       +
>       +# shellcheck disable=SC1091
>       +. ./test-lib.sh
>      @@ t/t2206-add-submodule-ignored.sh (new)
>       +'
>       +
>       +#6
>      -+# check that 'git add --force .' does not stage the change in the submodule
>      ++# check that 'git add --include-ignored-submodules .' does not stage the change in the submodule
>       +# and that 'git status' does not show it as modified
>      -+test_expect_success 'main: check --force add . and status'  '
>      ++test_expect_success 'main: check --include-ignored-submodules add . and status'  '
>       +	cd "${base_path}" &&
>       +	cd main &&
>      -+	GIT_TRACE=1 git add --force . &&
>      ++	GIT_TRACE=1 git add --include-ignored-submodules . &&
>       +	! git status --porcelain | grep "^M  sub$" &&
>       +	echo
>       +'
>      @@ t/t2206-add-submodule-ignored.sh (new)
>       +'
>       +
>       +#8
>      -+# check that 'git add --force sub' does stage the change in the submodule
>      -+# check that 'git add --force ./sub/' does stage the change in the submodule
>      ++# check that 'git add --include-ignored-submodules sub' does stage the change in the submodule
>      ++# check that 'git add --include-ignored-submodules ./sub/' does stage the change in the submodule
>       +# and that 'git status --porcelain' does show it as modified
>       +# commit it..
>       +# check that 'git log --ignore-submodules=none' shows the submodule change
>      @@ t/t2206-add-submodule-ignored.sh (new)
>       +test_expect_success 'main: check force add sub and ./sub/ and status'  '
>       +	cd "${base_path}" &&
>       +	cd main &&
>      -+	echo "Adding with --force should work: git add --force sub" &&
>      -+	GIT_TRACE=1 git add --force sub &&
>      ++	echo "Adding with --include-ignored-submodules should work: git add --include-ignored-submodules sub" &&
>      ++	GIT_TRACE=1 git add --include-ignored-submodules sub &&
>       +	git status --porcelain | grep "^M  sub$" &&
>       +	git restore --staged sub &&
>       +	! git status --porcelain | grep "^M  sub$" &&
>      -+	echo "Adding with --force should work: git add --force ./sub/" &&
>      -+	GIT_TRACE=1 git add --force ./sub/ &&
>      ++	echo "Adding with --include-ignored-submodules should work: git add --include-ignored-submodules ./sub/" &&
>      ++	GIT_TRACE=1 git add --include-ignored-submodules ./sub/ &&
>       +	git status --porcelain | grep "^M  sub$" &&
>       +	git commit -m "update submodule pointer" &&
>       +	! git status --porcelain | grep "^ M sub$" &&
>  4:  58563a7b90 ! 4:  93c95954f1 tests: fix existing tests when add an ignore=all submodule
>      @@ Metadata
>        ## Commit message ##
>           tests: fix existing tests when add an ignore=all submodule
>       
>      -    There are tests that rely on "git add <submodule>" also adds it. A --force
>      -    is needed with this enhancement hence they are added accordingly in these
>      -    tests.
>      +    There are tests that rely on "git add <submodule>" to add updates in the
>      +    parent repository. A new option --include-ignored-submodules is introduced
>      +    as it is now needed with this enhancement.
>       
>           Updated tests:
>           - t1013-read-tree-submodule.sh ( fixed in: t/lib-submodule-update.sh )
>      +    - t2013-checkout-submodule.sh ( fixed in: t/lib-submodule-update.sh )
>           - t7406-submodule-update.sh
>           - t7508-status.sh
>       
>      @@ t/lib-submodule-update.sh: create_lib_submodule_repo () {
>        			git push origin modifications
>        		) &&
>       -		git add sub1 &&
>      -+		git add --force sub1 &&
>      ++		git add --include-ignored-submodules sub1 &&
>        		git commit -m "Modify sub1" &&
>        
>        		git checkout -b add_nested_sub modify_sub1 &&
>      @@ t/lib-submodule-update.sh: create_lib_submodule_repo () {
>        		git -C sub1 submodule add --branch no_submodule ../submodule_update_sub2 sub2 &&
>        		git -C sub1 commit -a -m "add a nested submodule" &&
>       -		git add sub1 &&
>      -+		git add --force sub1 &&
>      ++		git add --include-ignored-submodules sub1 &&
>        		git commit -a -m "update submodule, that updates a nested submodule" &&
>        		git checkout -b modify_sub1_recursively &&
>        		git -C sub1 checkout -b modify_sub1_recursively &&
>      @@ t/lib-submodule-update.sh: create_lib_submodule_repo () {
>        		git -C sub1 add sub2 &&
>        		git -C sub1 commit -m "update nested sub" &&
>       -		git add sub1 &&
>      -+		git add --force sub1 &&
>      ++		git add --include-ignored-submodules sub1 &&
>        		git commit -m "update sub1, that updates nested sub" &&
>        		git -C sub1 push origin modify_sub1_recursively &&
>        		git -C sub1/sub2 push origin modify_sub1_recursively &&
>      @@ t/t7508-status.sh: test_expect_success 'git commit will commit a staged but igno
>        test_expect_success 'git commit --dry-run will show a staged but ignored submodule' '
>        	git reset HEAD^ &&
>       -	git add sm &&
>      -+	git add --force sm &&
>      ++	git add --include-ignored-submodules sm &&
>        	cat >expect << EOF &&
>        On branch main
>        Your branch and '\''upstream'\'' have diverged,
>  5:  416695f439 < -:  ---------- Documentation: update add --force and submodule ignore=all config
>  -:  ---------- > 5:  ee84190cd8 Documentation: add --include_ignored_submodules + ignore=all config
Junio C Hamano· Nov 13, 2025, 22:07 UTC · re: Claus Schneider(Eficode) via GitGitGadget · lore

Re: [PATCH v2 1/5] read-cache: update add_files_to_cache take param include_ignored_submodules

"Claus Schneider(Eficode) via GitGitGadget" <gitgitgadget@gmail.com> writes:

Show 8 quoted lines
> From: "Claus Schneider(Eficode)" <claus.schneider@eficode.com>
>
> The include_ignored_submodules parameter is added to the function
> add_files_to_cache for usage of explicit updating the index for the updated
> submodule using the explicit patchspec to the submodule.
>
> Signed-off-by: Claus Schneider(Eficode) <claus.schneider@eficode.com>
> ---

I still do not know enough if the overall idea of this topic is a good idea, but let me regiew the code change at the mechanical level (i.e., what needs fixing if these changes are good things to have).

Show 17 quoted lines
> diff --git a/builtin/add.c b/builtin/add.c
> index 0235854f80..6d11382f33 100644
> --- a/builtin/add.c
> +++ b/builtin/add.c
> @@ -233,6 +233,7 @@ N_("The following paths are ignored by one of your .gitignore files:\n");
>  static int verbose, show_only, ignored_too, refresh_only;
>  static int ignore_add_errors, intent_to_add, ignore_missing;
>  static int warn_on_embedded_repo = 1;
> +static int include_ignored_submodules;
>  
>  #define ADDREMOVE_DEFAULT 1
>  static int addremove = ADDREMOVE_DEFAULT;
> @@ -271,6 +272,7 @@ static struct option builtin_add_options[] = {
>  	OPT_BOOL( 0 , "ignore-errors", &ignore_add_errors, N_("just skip files which cannot be added because of errors")),
>  	OPT_BOOL( 0 , "ignore-missing", &ignore_missing, N_("check if - even missing - files are ignored in dry run")),
>  	OPT_BOOL(0, "sparse", &include_sparse, N_("allow updating entries outside of the sparse-checkout cone")),
> +    OPT_BOOL(0, "include-ignored-submodules", &include_ignored_submodules, N_("add submodules even if they has configuration ignore=all")),

Wrong indentation. Also, perhaps wrap this new line that is overly long (*WITHOUT* rewrapping existing overly long lines)?

>  			add_files_to_cache(the_repository, NULL, NULL, NULL, 0,
> -					   0);
> +					   0, 0 );
Our coding style does not allow an extra space after "(" or before ")".
Show 10 quoted lines
> diff --git a/read-cache-ll.h b/read-cache-ll.h
> index 71b49d9af4..2c8b4b21b1 100644
> --- a/read-cache-ll.h
> +++ b/read-cache-ll.h
> @@ -481,7 +481,7 @@ int cmp_cache_name_compare(const void *a_, const void *b_);
>  
>  int add_files_to_cache(struct repository *repo, const char *prefix,
>  		       const struct pathspec *pathspec, char *ps_matched,
> -		       int include_sparse, int flags);
> +		       int include_sparse, int flags, int ignored_too );

I am not sure if adding an extra parameter randomly like this is a good idea. Existing include_sparse is already a single bit that is stuffed in an int, so it might make sense to change it into a set of bits (i.e., "unsigned int") in one preliminary patch, and then your change can borrow another bit in the same flag word.

See the attached patch (not even compile tested, though) for an illustration of what such a "preliminary clean-up" step to get rid of the extra include_sparse parameter may look like.

Show 22 quoted lines
> +++ b/read-cache.c
> @@ -3880,9 +3880,12 @@ void overlay_tree_on_index(struct index_state *istate,
>  
>  struct update_callback_data {
>  	struct index_state *index;
> +	struct repository *repo;
> +	struct pathspec *pathspec;
>  	int include_sparse;
>  	int flags;
>  	int add_errors;
> +	int include_ignored_submodules;
>  };
>  
>  static int fix_unmerged_status(struct diff_filepair *p,
> @@ -3924,7 +3927,48 @@ static void update_callback(struct diff_queue_struct *q,
>  		default:
>  			die(_("unexpected diff status %c"), p->status);
>  		case DIFF_STATUS_MODIFIED:
> -		case DIFF_STATUS_TYPE_CHANGED:
> +		case DIFF_STATUS_TYPE_CHANGED: {
> +			struct stat st;
> +			if (!lstat(path, &st) && S_ISDIR(st.st_mode)) { // only consider submodule if it is a directory
/* Our single liner comment should look like this, not with double-slashes */

The fact that this block has to be so deeply indented strongly indicates that it should probably become a separate helper function.

I'll stop here for now.
 builtin/add.c      | 8 ++++----
 builtin/checkout.c | 3 +--
 builtin/commit.c   | 2 +-
 read-cache-ll.h    | 6 +++++-
 read-cache.c       | 8 +++-----
 5 files changed, 14 insertions(+), 13 deletions(-)
Show changes to diff +14 −13
diff --git c/builtin/add.c w/builtin/add.c
index 32709794b3..49d0199c0b 100644
--- c/builtin/add.c
+++ w/builtin/add.c
@@ -384,7 +384,7 @@ int cmd_add(int argc,
 	int exit_status = 0;
 	struct pathspec pathspec;
 	struct dir_struct dir = DIR_INIT;
-	int flags;
+	unsigned flags;
 	int add_new_files;
 	int require_pathspec;
 	char *seen = NULL;
@@ -485,7 +485,8 @@ int cmd_add(int argc,
 		 (intent_to_add ? ADD_CACHE_INTENT : 0) |
 		 (ignore_add_errors ? ADD_CACHE_IGNORE_ERRORS : 0) |
 		 (!(addremove || take_worktree_changes)
-		  ? ADD_CACHE_IGNORE_REMOVAL : 0));
+		  ? ADD_CACHE_IGNORE_REMOVAL : 0) |
+		 (include_sparse ? ADD_CACHE_INCLUDE_SPARSE : 0));
 
 	if (repo_read_index_preload(repo, &pathspec, 0) < 0)
 		die(_("index file corrupt"));
@@ -583,8 +584,7 @@ int cmd_add(int argc,
 		exit_status |= renormalize_tracked_files(repo, &pathspec, flags);
 	else
 		exit_status |= add_files_to_cache(repo, prefix,
-						  &pathspec, ps_matched,
-						  include_sparse, flags);
+						  &pathspec, ps_matched, flags);
 
 	if (take_worktree_changes && !add_renormalize && !ignore_add_errors &&
 	    report_path_error(ps_matched, &pathspec))
diff --git c/builtin/checkout.c w/builtin/checkout.c
index f9453473fe..766a8e3b66 100644
--- c/builtin/checkout.c
+++ w/builtin/checkout.c
@@ -898,8 +898,7 @@ static int merge_working_tree(const struct checkout_opts *opts,
 			 * entries in the index.
 			 */
 
-			add_files_to_cache(the_repository, NULL, NULL, NULL, 0,
-					   0);
+			add_files_to_cache(the_repository, NULL, NULL, NULL, 0);
 			init_ui_merge_options(&o, the_repository);
 			o.verbosity = 0;
 			work = write_in_core_index_as_tree(the_repository);
diff --git c/builtin/commit.c w/builtin/commit.c
index 0243f17d53..6e42534977 100644
--- c/builtin/commit.c
+++ w/builtin/commit.c
@@ -455,7 +455,7 @@ static const char *prepare_index(const char **argv, const char *prefix,
 		repo_hold_locked_index(the_repository, &index_lock,
 				       LOCK_DIE_ON_ERROR);
 		add_files_to_cache(the_repository, also ? prefix : NULL,
-				   &pathspec, ps_matched, 0, 0);
+				   &pathspec, ps_matched, 0);
 		if (!all && report_path_error(ps_matched, &pathspec))
 			exit(128);
 
diff --git c/read-cache-ll.h w/read-cache-ll.h
index 71b49d9af4..c9311f845b 100644
--- c/read-cache-ll.h
+++ w/read-cache-ll.h
@@ -390,11 +390,15 @@ int remove_index_entry_at(struct index_state *, int pos);
 
 void remove_marked_cache_entries(struct index_state *istate, int invalidate);
 int remove_file_from_index(struct index_state *, const char *path);
+
+/* add_files_to_cache() flags */
 #define ADD_CACHE_VERBOSE 1
 #define ADD_CACHE_PRETEND 2
 #define ADD_CACHE_IGNORE_ERRORS	4
 #define ADD_CACHE_IGNORE_REMOVAL 8
 #define ADD_CACHE_INTENT 16
+#define ADD_CACHE_INCLUDE_SPARSE 32
+
 /*
  * These two are used to add the contents of the file at path
  * to the index, marking the working tree up-to-date by storing
@@ -481,7 +485,7 @@ int cmp_cache_name_compare(const void *a_, const void *b_);
 
 int add_files_to_cache(struct repository *repo, const char *prefix,
 		       const struct pathspec *pathspec, char *ps_matched,
-		       int include_sparse, int flags);
+		       unsigned flags);
 
 void overlay_tree_on_index(struct index_state *istate,
 			   const char *tree_name, const char *prefix);
diff --git c/read-cache.c w/read-cache.c
index 032480d0c7..f32b642446 100644
--- c/read-cache.c
+++ w/read-cache.c
@@ -3881,8 +3881,7 @@ void overlay_tree_on_index(struct index_state *istate,
 
 struct update_callback_data {
 	struct index_state *index;
-	int include_sparse;
-	int flags;
+	unsigned flags;
 	int add_errors;
 };
 
@@ -3917,7 +3916,7 @@ static void update_callback(struct diff_queue_struct *q,
 		struct diff_filepair *p = q->queue[i];
 		const char *path = p->one->path;
 
-		if (!data->include_sparse &&
+		if (!(data->flags & ADD_CACHE_INCLUDE_SPARSE) &&
 		    !path_in_sparse_checkout(path, data->index))
 			continue;
 
@@ -3946,7 +3945,7 @@ static void update_callback(struct diff_queue_struct *q,
 
 int add_files_to_cache(struct repository *repo, const char *prefix,
 		       const struct pathspec *pathspec, char *ps_matched,
-		       int include_sparse, int flags)
+		       unsigned flags)
 {
 	struct odb_transaction *transaction;
 	struct update_callback_data data;
@@ -3954,7 +3953,6 @@ int add_files_to_cache(struct repository *repo, const char *prefix,
 
 	memset(&data, 0, sizeof(data));
 	data.index = repo->index;
-	data.include_sparse = include_sparse;
 	data.flags = flags;
 
 	repo_init_revisions(repo, &rev, prefix);
Claus Schneider· Nov 14, 2025, 13:53 UTC · re: Junio C Hamano · lore

Re: [PATCH v2 0/5] git-add : Respect submodule ignore=all and only add changes with --force

Thanks Junio - well received and noted. I have updated the PR description accordingly, but I have not changed the "--force" in the description even though I have implemented ''--include-ignored-submodules' as Philip had the input not to use "--force". He suggested using a new option. Philips comment:

Show 8 quoted lines
> I'm not convinced that the approach of using "--force" is a good idea as
> it conflates ignoring changes to tracked paths (which is what
> submodule.<name>.ignore" does) with ignoring untracked paths (which is
> what ".gitignore" does). If we're happy to break existing uses that rely
> on the current behavior then having a new option to override
> submodule.<name>.ignore strikes me as a better way forward. I don't have
> much experience of using submodules so I can't comment on whether
> changing the behavior is a good idea or not.

I think it will be more simple to use the '--force' option though and keep the amount of options lower and less to remember. Given your comments about more usages of bytes for option also becomes obsolete if we stick to "--force". I am happy to do so.

I am investigating your other comments on the patches in the meantime.
On Thu, Nov 13, 2025 at 8:58 PM Junio C Hamano <gitster@pobox.com> wrote:
Show 465 quoted lines
>
> "Claus Schneider via GitGitGadget" <gitgitgadget@gmail.com> writes:
>
> > The feature of configuring a submodule to "ignore=all" is nicely respected
> > in commands "status" and "diff".
>
> "nicely respected" is not very informative for those who do not know
> what the setting does.  Saying something like
>
>     "git status" and "git diff" will not report modified submodules
>     with submodule.<name>.ignore set to "all".
>
> would not waste significantly more bytes than what you wrote, and is
> more helpful.
>
> > However the "add" command does not respect
> > the configuration the same way.
>
> Again, "does not respect" and then what?  Running "git add" on a
> submodule with submodule.<name>.ignore set to "all" does what?
> Complains that it has changes but because .ignore is set it won't
> add?  Adds it silently?  Something else?
>
> > The behavior is problematic for the logic
> > between status/diff and add.
>
> After this sentence, "because ..." is missing.  Please help readers
> understand the issue you perceive as problematic more easily.
>
> I am guessing that you are assuming that an "add", after "diff" or
> "status" said there is no change, is expected to be a no-op, but I
> cannot be sure if that is what you are referring to here with the
> reason left unsaid like the above.
>
> > Secondly it makes it problematic to track
> > branches in the submodule configuration as developers unintentionally keeps
> > add submodule updates and get conflicts for no intentional reason. Both adds
> > unnecessary friction to the usage of submodules.
> >
> > The patches implement the same logical behavior for ignore=all submodules as
> > regular ignored files. The status now does not show any diff - nor will the
> > add command update the reference submodule reference. If you add the
> > submodule path which is ignore=all then you are presented with a message
> > that you need to use the --force option.
>
> I vaguely recall that an earlier discussion between you and Phillip
> were concluding against "--force"?  I personally feel it is in line
> with "git add foo.o" (when '*.o' is in .gitignore) gets rejected and
> "git add -f foo.o" is a way to override it, but in the list of
> patches below, I see --include-ignored-submodules (no, our command
> line option names do not use underscore for inter-word-gaps), so I
> suspect the description in the cover letter around here is stale?
>
>
> > The branch=, ignore=all (and
> > update=none) now works great with update --remote,
>
> Again, "great" is not very informative, and as bad as "nicely
> respected".  Avoid using these adjectives loaded with unnecessary
> value judgements, and instead trust your readers.  They are
> intelligent to judge if the updated behaviour is great or not for
> themselves.  Try to use the same bytes on helping readers understand
> what actually happens.
>
> > but developers does not
>
> "do not".
>
> > have to consider changes in the updates of the submodule sha1. The
> > implementation removes a friction of working with submodules and can be used
> > like the repo tool with branches configured. The submodule status report
> > could be used for build/release documentation for reproduction of a setup.
> >
> > A few tests used the adding of submodules without --force, hence they have
> > been updated to use the --force option.
> >
> > Claus Schneider(Eficode) (5):
> >   read-cache: update add_files_to_cache take param
> >     include_ignored_submodules
> >   read-cache: add/read-cache respect submodule ignore=all
> >   tests: add new t2206-add-submodule-ignored.sh to test ignore=all
> >     scenario
> >   tests: fix existing tests when add an ignore=all submodule
> >   Documentation: add --include_ignored_submodules + ignore=all config
> >
> >  .devcontainer/Dockerfile            |  70 +++++++++++++++
> >  .devcontainer/Dockerfile.standalone |  76 ++++++++++++++++
> >  .devcontainer/devcontainer.json     |  25 ++++++
> >  Documentation/config/submodule.adoc |  13 +--
> >  Documentation/git-add.adoc          |   5 ++
> >  Documentation/gitmodules.adoc       |   5 +-
> >  builtin/add.c                       |   4 +-
> >  builtin/checkout.c                  |   2 +-
> >  builtin/commit.c                    |   2 +-
> >  read-cache-ll.h                     |   2 +-
> >  read-cache.c                        |  54 ++++++++++-
> >  t/lib-submodule-update.sh           |   6 +-
> >  t/meson.build                       |   1 +
> >  t/t2206-add-submodule-ignored.sh    | 134 ++++++++++++++++++++++++++++
> >  t/t7508-status.sh                   |   2 +-
> >  15 files changed, 384 insertions(+), 17 deletions(-)
> >  create mode 100644 .devcontainer/Dockerfile
> >  create mode 100644 .devcontainer/Dockerfile.standalone
> >  create mode 100644 .devcontainer/devcontainer.json
> >  create mode 100755 t/t2206-add-submodule-ignored.sh
> >
> >
> > base-commit: 81f86aacc4eb74cdb9c2c8082d36d2070c666045
> > Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-1987%2FPraqma%2Frespect-submodule-ignore-v2
> > Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-1987/Praqma/respect-submodule-ignore-v2
> > Pull-Request: https://github.com/gitgitgadget/git/pull/1987
> >
> > Range-diff vs v1:
> >
> >  1:  d98cca698d ! 1:  5796009122 read-cache: update add_files_to_cache to take param ignored_too(--force)
> >      @@ Metadata
> >       Author: Claus Schneider(Eficode) <claus.schneider@eficode.com>
> >
> >        ## Commit message ##
> >      -    read-cache: update add_files_to_cache to take param ignored_too(--force)
> >      +    read-cache: update add_files_to_cache take param include_ignored_submodules
> >
> >      -    The ignored_too parameter is added to the function add_files_to_cache for
> >      -    usage of explicit updating the index for the updated submodule using the
> >      -    explicit patchspec to the submodule.
> >      +    The include_ignored_submodules parameter is added to the function
> >      +    add_files_to_cache for usage of explicit updating the index for the updated
> >      +    submodule using the explicit patchspec to the submodule.
> >
> >           Signed-off-by: Claus Schneider(Eficode) <claus.schneider@eficode.com>
> >
> >        ## builtin/add.c ##
> >      +@@ builtin/add.c: N_("The following paths are ignored by one of your .gitignore files:\n");
> >      + static int verbose, show_only, ignored_too, refresh_only;
> >      + static int ignore_add_errors, intent_to_add, ignore_missing;
> >      + static int warn_on_embedded_repo = 1;
> >      ++static int include_ignored_submodules;
> >      +
> >      + #define ADDREMOVE_DEFAULT 1
> >      + static int addremove = ADDREMOVE_DEFAULT;
> >      +@@ builtin/add.c: static struct option builtin_add_options[] = {
> >      +        OPT_BOOL( 0 , "ignore-errors", &ignore_add_errors, N_("just skip files which cannot be added because of errors")),
> >      +        OPT_BOOL( 0 , "ignore-missing", &ignore_missing, N_("check if - even missing - files are ignored in dry run")),
> >      +        OPT_BOOL(0, "sparse", &include_sparse, N_("allow updating entries outside of the sparse-checkout cone")),
> >      ++    OPT_BOOL(0, "include-ignored-submodules", &include_ignored_submodules, N_("add submodules even if they has configuration ignore=all")),
> >      +        OPT_STRING(0, "chmod", &chmod_arg, "(+|-)x",
> >      +                   N_("override the executable bit of the listed files")),
> >      +        OPT_HIDDEN_BOOL(0, "warn-embedded-repo", &warn_on_embedded_repo,
> >       @@ builtin/add.c: int cmd_add(int argc,
> >               else
> >                       exit_status |= add_files_to_cache(repo, prefix,
> >                                                         &pathspec, ps_matched,
> >       -                                                 include_sparse, flags);
> >      -+                                                 include_sparse, flags, ignored_too);
> >      ++                                                 include_sparse, flags, include_ignored_submodules);
> >
> >               if (take_worktree_changes && !add_renormalize && !ignore_add_errors &&
> >                   report_path_error(ps_matched, &pathspec))
> >      @@ read-cache.c: void overlay_tree_on_index(struct index_state *istate,
> >               int include_sparse;
> >               int flags;
> >               int add_errors;
> >      -+       int ignored_too;
> >      ++       int include_ignored_submodules;
> >        };
> >
> >        static int fix_unmerged_status(struct diff_filepair *p,
> >       @@ read-cache.c: static void update_callback(struct diff_queue_struct *q,
> >      +                default:
> >      +                        die(_("unexpected diff status %c"), p->status);
> >      +                case DIFF_STATUS_MODIFIED:
> >      +-               case DIFF_STATUS_TYPE_CHANGED:
> >      ++               case DIFF_STATUS_TYPE_CHANGED: {
> >      ++                       struct stat st;
> >      ++                       if (!lstat(path, &st) && S_ISDIR(st.st_mode)) { // only consider submodule if it is a directory
> >      ++                               const struct submodule *sub = submodule_from_path(data->repo, null_oid(the_hash_algo), path);
> >      ++                               if (sub && sub->name && sub->ignore && !strcmp(sub->ignore, "all")) {
> >      ++                                       int pathspec_matches = 0;
> >      ++                                       char *norm_pathspec = NULL;
> >      ++                                       int ps_i;
> >      ++                                       trace_printf("ignore=all %s\n", path);
> >      ++                                       trace_printf("pathspec %s\n",
> >      ++                                                       (data->pathspec && data->pathspec->nr) ? "has pathspec" : "no pathspec");
> >      ++                                       /* Safely scan all pathspec items (q->nr may exceed pathspec->nr). */
> >      ++                                       if (data->pathspec) {
> >      ++                                               for (ps_i = 0; ps_i < data->pathspec->nr; ps_i++) {
> >      ++                                                       const char *m = data->pathspec->items[ps_i].match;
> >      ++                                                       if (!m)
> >      ++                                                               continue;
> >      ++                                                       norm_pathspec = xstrdup(m);
> >      ++                                                       strip_dir_trailing_slashes(norm_pathspec);
> >      ++                                                       if (!strcmp(path, norm_pathspec)) {
> >      ++                                                               pathspec_matches = 1;
> >      ++                                                               FREE_AND_NULL(norm_pathspec);
> >      ++                                                               break;
> >      ++                                                       }
> >      ++                                                       FREE_AND_NULL(norm_pathspec);
> >      ++                                               }
> >      ++                                       }
> >      ++                                       if (pathspec_matches) {
> >      ++                                               if (data->include_ignored_submodules && data->include_ignored_submodules > 0) {
> >      ++                                                       trace_printf("Add ignored=all submodule due to --include_ignored_submodules: %s\n", path);
> >      ++                                               } else {
> >      ++                                                       printf(_("Skipping submodule due to ignore=all: %s"), path);
> >      ++                                                       printf(_("Use --include_ignored_submodules, if you really want to add them.") );
> >      ++                                                       continue;
> >      ++                                               }
> >      ++                                       } else {
> >      ++                                               /* No explicit pathspec match -> skip silently (or with trace). */
> >      ++                                               trace_printf("pathspec does not match %s\n", path);
> >      ++                                               continue;
> >      ++                                       }
> >      ++                               }
> >      ++                       }
> >      +                        if (add_file_to_index(data->index, path, data->flags)) {
> >      +                                if (!(data->flags & ADD_CACHE_IGNORE_ERRORS))
> >      +                                        die(_("updating files failed"));
> >      +@@ read-cache.c: static void update_callback(struct diff_queue_struct *q,
> >
> >        int add_files_to_cache(struct repository *repo, const char *prefix,
> >                              const struct pathspec *pathspec, char *ps_matched,
> >       -                      int include_sparse, int flags)
> >      -+                      int include_sparse, int flags, int ignored_too )
> >      ++                      int include_sparse, int flags, int include_ignored_submodules )
> >        {
> >               struct update_callback_data data;
> >               struct rev_info rev;
> >      @@ read-cache.c: int add_files_to_cache(struct repository *repo, const char *prefix
> >               data.include_sparse = include_sparse;
> >               data.flags = flags;
> >       +       data.repo = repo;
> >      -+       data.ignored_too = ignored_too;
> >      ++       data.include_ignored_submodules = include_ignored_submodules;
> >       +       data.pathspec = (struct pathspec *)pathspec;
> >
> >               repo_init_revisions(repo, &rev, prefix);
> >  2:  d1b02617e6 ! 2:  9ec79b9a11 read-cache: let read-cache respect submodule ignore=all and --force
> >      @@ Metadata
> >       Author: Claus Schneider(Eficode) <claus.schneider@eficode.com>
> >
> >        ## Commit message ##
> >      -    read-cache: let read-cache respect submodule ignore=all and --force
> >      +    read-cache: add/read-cache respect submodule ignore=all
> >
> >      -    Given the submdule configuration is ignore=all then only update the
> >      -    submdule if the --force option is given and the submodule is explicit
> >      -    given in the pathspec.
> >      +    Submodules configured with ignore=all are now skipped during add operations
> >      +    unless overridden by --include-ignored-submodules and the submodule path is
> >      +    explicitly specified.
> >
> >           A message is printed (like ignored files) guiding the user to use the
> >      -    --force flag if the user has explicitely want to update the submodule
> >      -    reference.
> >      +    --include-ignored-submodules flag if the user has explicitely want to update
> >      +    the submodule reference.
> >
> >           The reason for the change is support submodule branch tracking or
> >           similar and git status state nothing and git add should not add either.
> >      @@ Commit message
> >           the submodule is already tracked.
> >
> >           The change opens up a lot of possibilities for submodules to be used
> >      -    more freely and a like the repo tool. A submodule can be added for many
> >      +    more freely and simular to the repo tool. A submodule can be added for many
> >           more reason and loosely coupled dependencies to the super repo which often
> >           gives the friction of handle the explicit commits and updates without
> >           the need for tracking the submodule sha1 by sha1.
> >      @@ read-cache.c
> >        /* Mask for the name length in ce_flags in the on-disk index */
> >
> >       @@ read-cache.c: static void update_callback(struct diff_queue_struct *q,
> >      -                default:
> >      -                        die(_("unexpected diff status %c"), p->status);
> >      -                case DIFF_STATUS_MODIFIED:
> >      --               case DIFF_STATUS_TYPE_CHANGED:
> >      -+               case DIFF_STATUS_TYPE_CHANGED: {
> >      -+                       struct stat st;
> >      -+                       if (!lstat(path, &st) && S_ISDIR(st.st_mode)) { // only consider submodule if it is a directory
> >      -+                               const struct submodule *sub = submodule_from_path(data->repo, null_oid(the_hash_algo), path);
> >      -+                               if (sub && sub->name && sub->ignore && !strcmp(sub->ignore, "all")) {
> >      -+                                       int pathspec_matches = 0;
> >      -+                                       char *norm_pathspec = NULL;
> >      -+                                       int ps_i;
> >      -+                                       trace_printf("ignore=all %s\n", path);
> >      -+                                       trace_printf("pathspec %s\n",
> >      -+                                                       (data->pathspec && data->pathspec->nr) ? "has pathspec" : "no pathspec");
> >      -+                                       /* Safely scan all pathspec items (q->nr may exceed pathspec->nr). */
> >      -+                                       if (data->pathspec) {
> >      -+                                               for (ps_i = 0; ps_i < data->pathspec->nr; ps_i++) {
> >      -+                                                       const char *m = data->pathspec->items[ps_i].match;
> >      -+                                                       if (!m)
> >      -+                                                               continue;
> >      -+                                                       norm_pathspec = xstrdup(m);
> >      -+                                                       strip_dir_trailing_slashes(norm_pathspec);
> >      -+                                                       if (!strcmp(path, norm_pathspec)) {
> >      -+                                                               pathspec_matches = 1;
> >      -+                                                               FREE_AND_NULL(norm_pathspec);
> >      -+                                                               break;
> >      -+                                                       }
> >      -+                                                       FREE_AND_NULL(norm_pathspec);
> >      -+                                               }
> >      -+                                       }
> >      -+                                       if (pathspec_matches) {
> >      -+                                               if (data->ignored_too && data->ignored_too > 0) {
> >      -+                                                       trace_printf("Forcing add of submodule ignored=all due to --force: %s\n", path);
> >      -+                                               } else {
> >      -+                                                       printf(_("Skipping submodule due to ignore=all: %s"), path);
> >      -+                                                       printf(_("Use -f if you really want to add them.") );
> >      -+                                                       continue;
> >      -+                                               }
> >      -+                                       } else {
> >      -+                                               /* No explicit pathspec match -> skip silently (or with trace). */
> >      -+                                               trace_printf("pathspec does not match %s\n", path);
> >      -+                                               continue;
> >      -+                                       }
> >      -+                               }
> >      -+                       }
> >      -                        if (add_file_to_index(data->index, path, data->flags)) {
> >      -                                if (!(data->flags & ADD_CACHE_IGNORE_ERRORS))
> >      -                                        die(_("updating files failed"));
> >      +                                        }
> >      +                                        if (pathspec_matches) {
> >      +                                                if (data->include_ignored_submodules && data->include_ignored_submodules > 0) {
> >      +-                                                       trace_printf("Add ignored=all submodule due to --include_ignored_submodules: %s\n", path);
> >      ++                                                       trace_printf("Add submodule due to --include_ignored_submodules: %s\n", path);
> >      +                                                } else {
> >      +                                                        printf(_("Skipping submodule due to ignore=all: %s"), path);
> >      +                                                        printf(_("Use --include_ignored_submodules, if you really want to add them.") );
> >      +@@ read-cache.c: static void update_callback(struct diff_queue_struct *q,
> >      +                                                }
> >      +                                        } else {
> >      +                                                /* No explicit pathspec match -> skip silently (or with trace). */
> >      +-                                               trace_printf("pathspec does not match %s\n", path);
> >      ++                                               trace_printf("Pathspec to submodule does not match explicitly: %s\n", path);
> >      +                                                continue;
> >      +                                        }
> >      +                                }
> >      +@@ read-cache.c: static void update_callback(struct diff_queue_struct *q,
> >                                       data->add_errors++;
> >                               }
> >                               break;
> >  3:  8f3d5f7ec1 ! 3:  399a153b95 tests: add new t2206-add-submodule-ignored.sh to test ignore=all scenario
> >      @@ Commit message
> >           config with ignore=all also behaves as intended with configuration in
> >           .gitmodules and configuration given on the command line.
> >
> >      -    Testfile is added to meson.build for execution.
> >      +    The usage of --include_ignored_submodules is showcased and tested in the
> >      +    test suite.
> >      +
> >      +    The test file is added to meson.build for execution.
> >
> >           Signed-off-by: Claus Schneider(Eficode) <claus.schneider@eficode.com>
> >
> >      @@ t/t2206-add-submodule-ignored.sh (new)
> >       +# This test covers the behavior of "git add", "git status" and "git log" when
> >       +# dealing with submodules that have the ignore=all setting in
> >       +# .gitmodules. It ensures that changes in such submodules are
> >      -+# ignored by default, but can be staged with "git add --force".
> >      ++# ignored by default, but can be staged with "git add --include-ignored-submodules".
> >       +
> >       +# shellcheck disable=SC1091
> >       +. ./test-lib.sh
> >      @@ t/t2206-add-submodule-ignored.sh (new)
> >       +'
> >       +
> >       +#6
> >      -+# check that 'git add --force .' does not stage the change in the submodule
> >      ++# check that 'git add --include-ignored-submodules .' does not stage the change in the submodule
> >       +# and that 'git status' does not show it as modified
> >      -+test_expect_success 'main: check --force add . and status'  '
> >      ++test_expect_success 'main: check --include-ignored-submodules add . and status'  '
> >       +       cd "${base_path}" &&
> >       +       cd main &&
> >      -+       GIT_TRACE=1 git add --force . &&
> >      ++       GIT_TRACE=1 git add --include-ignored-submodules . &&
> >       +       ! git status --porcelain | grep "^M  sub$" &&
> >       +       echo
> >       +'
> >      @@ t/t2206-add-submodule-ignored.sh (new)
> >       +'
> >       +
> >       +#8
> >      -+# check that 'git add --force sub' does stage the change in the submodule
> >      -+# check that 'git add --force ./sub/' does stage the change in the submodule
> >      ++# check that 'git add --include-ignored-submodules sub' does stage the change in the submodule
> >      ++# check that 'git add --include-ignored-submodules ./sub/' does stage the change in the submodule
> >       +# and that 'git status --porcelain' does show it as modified
> >       +# commit it..
> >       +# check that 'git log --ignore-submodules=none' shows the submodule change
> >      @@ t/t2206-add-submodule-ignored.sh (new)
> >       +test_expect_success 'main: check force add sub and ./sub/ and status'  '
> >       +       cd "${base_path}" &&
> >       +       cd main &&
> >      -+       echo "Adding with --force should work: git add --force sub" &&
> >      -+       GIT_TRACE=1 git add --force sub &&
> >      ++       echo "Adding with --include-ignored-submodules should work: git add --include-ignored-submodules sub" &&
> >      ++       GIT_TRACE=1 git add --include-ignored-submodules sub &&
> >       +       git status --porcelain | grep "^M  sub$" &&
> >       +       git restore --staged sub &&
> >       +       ! git status --porcelain | grep "^M  sub$" &&
> >      -+       echo "Adding with --force should work: git add --force ./sub/" &&
> >      -+       GIT_TRACE=1 git add --force ./sub/ &&
> >      ++       echo "Adding with --include-ignored-submodules should work: git add --include-ignored-submodules ./sub/" &&
> >      ++       GIT_TRACE=1 git add --include-ignored-submodules ./sub/ &&
> >       +       git status --porcelain | grep "^M  sub$" &&
> >       +       git commit -m "update submodule pointer" &&
> >       +       ! git status --porcelain | grep "^ M sub$" &&
> >  4:  58563a7b90 ! 4:  93c95954f1 tests: fix existing tests when add an ignore=all submodule
> >      @@ Metadata
> >        ## Commit message ##
> >           tests: fix existing tests when add an ignore=all submodule
> >
> >      -    There are tests that rely on "git add <submodule>" also adds it. A --force
> >      -    is needed with this enhancement hence they are added accordingly in these
> >      -    tests.
> >      +    There are tests that rely on "git add <submodule>" to add updates in the
> >      +    parent repository. A new option --include-ignored-submodules is introduced
> >      +    as it is now needed with this enhancement.
> >
> >           Updated tests:
> >           - t1013-read-tree-submodule.sh ( fixed in: t/lib-submodule-update.sh )
> >      +    - t2013-checkout-submodule.sh ( fixed in: t/lib-submodule-update.sh )
> >           - t7406-submodule-update.sh
> >           - t7508-status.sh
> >
> >      @@ t/lib-submodule-update.sh: create_lib_submodule_repo () {
> >                               git push origin modifications
> >                       ) &&
> >       -               git add sub1 &&
> >      -+               git add --force sub1 &&
> >      ++               git add --include-ignored-submodules sub1 &&
> >                       git commit -m "Modify sub1" &&
> >
> >                       git checkout -b add_nested_sub modify_sub1 &&
> >      @@ t/lib-submodule-update.sh: create_lib_submodule_repo () {
> >                       git -C sub1 submodule add --branch no_submodule ../submodule_update_sub2 sub2 &&
> >                       git -C sub1 commit -a -m "add a nested submodule" &&
> >       -               git add sub1 &&
> >      -+               git add --force sub1 &&
> >      ++               git add --include-ignored-submodules sub1 &&
> >                       git commit -a -m "update submodule, that updates a nested submodule" &&
> >                       git checkout -b modify_sub1_recursively &&
> >                       git -C sub1 checkout -b modify_sub1_recursively &&
> >      @@ t/lib-submodule-update.sh: create_lib_submodule_repo () {
> >                       git -C sub1 add sub2 &&
> >                       git -C sub1 commit -m "update nested sub" &&
> >       -               git add sub1 &&
> >      -+               git add --force sub1 &&
> >      ++               git add --include-ignored-submodules sub1 &&
> >                       git commit -m "update sub1, that updates nested sub" &&
> >                       git -C sub1 push origin modify_sub1_recursively &&
> >                       git -C sub1/sub2 push origin modify_sub1_recursively &&
> >      @@ t/t7508-status.sh: test_expect_success 'git commit will commit a staged but igno
> >        test_expect_success 'git commit --dry-run will show a staged but ignored submodule' '
> >               git reset HEAD^ &&
> >       -       git add sm &&
> >      -+       git add --force sm &&
> >      ++       git add --include-ignored-submodules sm &&
> >               cat >expect << EOF &&
> >        On branch main
> >        Your branch and '\''upstream'\'' have diverged,
> >  5:  416695f439 < -:  ---------- Documentation: update add --force and submodule ignore=all config
> >  -:  ---------- > 5:  ee84190cd8 Documentation: add --include_ignored_submodules + ignore=all config
Claus Schneider via GitGitGadget· Jan 14, 2026, 07:47 UTC · re: Claus Schneider via GitGitGadget · lore

[PATCH v3 0/5] git-add: Skip submodules with ignore=all unless --force and explicit path used

The ignore=all configuration for submodules is currently honored by status and diff, but not by add. This inconsistency causes friction when working with submodules:

 * Developers unintentionally stage submodule updates, leading to conflicts
   and unnecessary changes.
 * Tracking branches in submodule configs causes friction as updates to the
   submodule SHA1 are added without intent.
This patch aligns git add with the behavior of status and diff:
 * Submodules marked ignore=all are skipped by default.
 * Attempting to add such a submodule explicitly now requires --force.

A submodule can frictionless track a branch in the configuration or manually switched to and use update --update --remote without unintentionally add the changes to the super-project.

Tests that previously added submodules without --force have been updated accordingly. A new test is added to test the behavior of git add with and without --force.

Claus Schneider(Eficode) (5):
  read-cache: update add_files_to_cache take param ignored_too
  read-cache: submodule add need --force given ignore=all configuration
  tests: t2206-add-submodule-ignored: ignore=all and add --force tests
  tests: fix existing tests when add an ignore=all submodule
  Documentation: update add --force option + ignore=all config
 Documentation/config/submodule.adoc |  13 +--
 Documentation/git-add.adoc          |   5 +-
 Documentation/gitmodules.adoc       |   5 +-
 builtin/add.c                       |   2 +-
 builtin/checkout.c                  |   2 +-
 builtin/commit.c                    |   2 +-
 read-cache-ll.h                     |   2 +-
 read-cache.c                        |  80 ++++++++++++++++-
 t/lib-submodule-update.sh           |   6 +-
 t/meson.build                       |   1 +
 t/t2206-add-submodule-ignored.sh    | 134 ++++++++++++++++++++++++++++
 t/t7508-status.sh                   |   2 +-
 12 files changed, 235 insertions(+), 19 deletions(-)
 create mode 100755 t/t2206-add-submodule-ignored.sh
base-commit: 9a2fb147f2c61d0cab52c883e7e26f5b7948e3ed
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-1987%2FPraqma%2Frespect-submodule-ignore-v3
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-1987/Praqma/respect-submodule-ignore-v3
Pull-Request: https://github.com/gitgitgadget/git/pull/1987
Range-diff vs v2:
 1:  5796009122 ! 1:  d2b66286c2 read-cache: update add_files_to_cache take param include_ignored_submodules
     @@ Metadata
      Author: Claus Schneider(Eficode) <claus.schneider@eficode.com>
      
       ## Commit message ##
     -    read-cache: update add_files_to_cache take param include_ignored_submodules
     +    read-cache: update add_files_to_cache take param ignored_too
      
     -    The include_ignored_submodules parameter is added to the function
     +    The ignored_too parameter is added to the function
          add_files_to_cache for usage of explicit updating the index for the updated
          submodule using the explicit patchspec to the submodule.
      
          Signed-off-by: Claus Schneider(Eficode) <claus.schneider@eficode.com>
      
       ## builtin/add.c ##
     -@@ builtin/add.c: N_("The following paths are ignored by one of your .gitignore files:\n");
     - static int verbose, show_only, ignored_too, refresh_only;
     - static int ignore_add_errors, intent_to_add, ignore_missing;
     - static int warn_on_embedded_repo = 1;
     -+static int include_ignored_submodules;
     - 
     - #define ADDREMOVE_DEFAULT 1
     - static int addremove = ADDREMOVE_DEFAULT;
     -@@ builtin/add.c: static struct option builtin_add_options[] = {
     - 	OPT_BOOL( 0 , "ignore-errors", &ignore_add_errors, N_("just skip files which cannot be added because of errors")),
     - 	OPT_BOOL( 0 , "ignore-missing", &ignore_missing, N_("check if - even missing - files are ignored in dry run")),
     - 	OPT_BOOL(0, "sparse", &include_sparse, N_("allow updating entries outside of the sparse-checkout cone")),
     -+    OPT_BOOL(0, "include-ignored-submodules", &include_ignored_submodules, N_("add submodules even if they has configuration ignore=all")),
     - 	OPT_STRING(0, "chmod", &chmod_arg, "(+|-)x",
     - 		   N_("override the executable bit of the listed files")),
     - 	OPT_HIDDEN_BOOL(0, "warn-embedded-repo", &warn_on_embedded_repo,
      @@ builtin/add.c: int cmd_add(int argc,
       	else
       		exit_status |= add_files_to_cache(repo, prefix,
       						  &pathspec, ps_matched,
      -						  include_sparse, flags);
     -+						  include_sparse, flags, include_ignored_submodules);
     ++						  include_sparse, flags, ignored_too);
       
       	if (take_worktree_changes && !add_renormalize && !ignore_add_errors &&
       	    report_path_error(ps_matched, &pathspec))
     @@ builtin/checkout.c: static int merge_working_tree(const struct checkout_opts *op
       
       			add_files_to_cache(the_repository, NULL, NULL, NULL, 0,
      -					   0);
     -+					   0, 0 );
     ++					0, 0);
       			init_ui_merge_options(&o, the_repository);
       			o.verbosity = 0;
       			work = write_in_core_index_as_tree(the_repository);
     @@ read-cache.c: void overlay_tree_on_index(struct index_state *istate,
       	int include_sparse;
       	int flags;
       	int add_errors;
     -+	int include_ignored_submodules;
     ++	int ignored_too;
       };
       
       static int fix_unmerged_status(struct diff_filepair *p,
     @@ read-cache.c: static void update_callback(struct diff_queue_struct *q,
       		case DIFF_STATUS_MODIFIED:
      -		case DIFF_STATUS_TYPE_CHANGED:
      +		case DIFF_STATUS_TYPE_CHANGED: {
     -+			struct stat st;
     -+			if (!lstat(path, &st) && S_ISDIR(st.st_mode)) { // only consider submodule if it is a directory
     -+				const struct submodule *sub = submodule_from_path(data->repo, null_oid(the_hash_algo), path);
     -+				if (sub && sub->name && sub->ignore && !strcmp(sub->ignore, "all")) {
     -+					int pathspec_matches = 0;
     -+					char *norm_pathspec = NULL;
     -+					int ps_i;
     -+					trace_printf("ignore=all %s\n", path);
     -+					trace_printf("pathspec %s\n",
     -+							(data->pathspec && data->pathspec->nr) ? "has pathspec" : "no pathspec");
     -+					/* Safely scan all pathspec items (q->nr may exceed pathspec->nr). */
     -+					if (data->pathspec) {
     -+						for (ps_i = 0; ps_i < data->pathspec->nr; ps_i++) {
     -+							const char *m = data->pathspec->items[ps_i].match;
     -+							if (!m)
     -+								continue;
     -+							norm_pathspec = xstrdup(m);
     -+							strip_dir_trailing_slashes(norm_pathspec);
     -+							if (!strcmp(path, norm_pathspec)) {
     -+								pathspec_matches = 1;
     -+								FREE_AND_NULL(norm_pathspec);
     -+								break;
     -+							}
     -+							FREE_AND_NULL(norm_pathspec);
     -+						}
     -+					}
     -+					if (pathspec_matches) {
     -+						if (data->include_ignored_submodules && data->include_ignored_submodules > 0) {
     -+							trace_printf("Add ignored=all submodule due to --include_ignored_submodules: %s\n", path);
     -+						} else {
     -+							printf(_("Skipping submodule due to ignore=all: %s"), path);
     -+							printf(_("Use --include_ignored_submodules, if you really want to add them.") );
     -+							continue;
     -+						}
     -+					} else {
     -+						/* No explicit pathspec match -> skip silently (or with trace). */
     -+						trace_printf("pathspec does not match %s\n", path);
     -+						continue;
     -+					}
     -+				}
     -+			}
       			if (add_file_to_index(data->index, path, data->flags)) {
       				if (!(data->flags & ADD_CACHE_IGNORE_ERRORS))
       					die(_("updating files failed"));
     @@ read-cache.c: static void update_callback(struct diff_queue_struct *q,
       int add_files_to_cache(struct repository *repo, const char *prefix,
       		       const struct pathspec *pathspec, char *ps_matched,
      -		       int include_sparse, int flags)
     -+		       int include_sparse, int flags, int include_ignored_submodules )
     ++		       int include_sparse, int flags, int ignored_too )
       {
     + 	struct odb_transaction *transaction;
       	struct update_callback_data data;
     - 	struct rev_info rev;
      @@ read-cache.c: int add_files_to_cache(struct repository *repo, const char *prefix,
       	data.index = repo->index;
       	data.include_sparse = include_sparse;
       	data.flags = flags;
      +	data.repo = repo;
     -+	data.include_ignored_submodules = include_ignored_submodules;
     ++	data.ignored_too = ignored_too;
      +	data.pathspec = (struct pathspec *)pathspec;
       
       	repo_init_revisions(repo, &rev, prefix);
 2:  9ec79b9a11 ! 2:  de72bf0a91 read-cache: add/read-cache respect submodule ignore=all
     @@ Metadata
      Author: Claus Schneider(Eficode) <claus.schneider@eficode.com>
      
       ## Commit message ##
     -    read-cache: add/read-cache respect submodule ignore=all
     +    read-cache: submodule add need --force given ignore=all configuration
      
          Submodules configured with ignore=all are now skipped during add operations
     -    unless overridden by --include-ignored-submodules and the submodule path is
     -    explicitly specified.
     +    unless overridden by --force and the submodule path is explicitly specified.
      
          A message is printed (like ignored files) guiding the user to use the
     -    --include-ignored-submodules flag if the user has explicitely want to update
     -    the submodule reference.
     +    --force flag if the user has explicitely want to update the submodule
     +    reference.
      
          The reason for the change is support submodule branch tracking or
     -    similar and git status state nothing and git add should not add either.
     -    The workflow is more logic and similar to regular ignored files even
     -    the submodule is already tracked.
     +    similar and git status states nothing and git add should not add either
     +    as a default behaviour. The workflow is more logic and similar to regular
     +    ignored files even the submodule is already tracked.
      
          The change opens up a lot of possibilities for submodules to be used
          more freely and simular to the repo tool. A submodule can be added for many
     @@ read-cache.c
       #include "hook.h"
      +#include "submodule.h"
      +#include "submodule-config.h"
     ++#include "advice.h"
       
       /* Mask for the name length in ce_flags in the on-disk index */
       
     -@@ read-cache.c: static void update_callback(struct diff_queue_struct *q,
     - 					}
     - 					if (pathspec_matches) {
     - 						if (data->include_ignored_submodules && data->include_ignored_submodules > 0) {
     --							trace_printf("Add ignored=all submodule due to --include_ignored_submodules: %s\n", path);
     -+							trace_printf("Add submodule due to --include_ignored_submodules: %s\n", path);
     - 						} else {
     - 							printf(_("Skipping submodule due to ignore=all: %s"), path);
     - 							printf(_("Use --include_ignored_submodules, if you really want to add them.") );
     -@@ read-cache.c: static void update_callback(struct diff_queue_struct *q,
     - 						}
     - 					} else {
     - 						/* No explicit pathspec match -> skip silently (or with trace). */
     --						trace_printf("pathspec does not match %s\n", path);
     -+						trace_printf("Pathspec to submodule does not match explicitly: %s\n", path);
     - 						continue;
     - 					}
     - 				}
     -@@ read-cache.c: static void update_callback(struct diff_queue_struct *q,
     - 				data->add_errors++;
     - 			}
     - 			break;
     +@@ read-cache.c: static int fix_unmerged_status(struct diff_filepair *p,
     + 		return DIFF_STATUS_MODIFIED;
     + }
     + 
     ++static int skip_submodule(const char *path,
     ++						struct repository *repo,
     ++						struct pathspec *pathspec,
     ++						int ignored_too)
     ++{
     ++    struct stat st;
     ++    const struct submodule *sub;
     ++    int pathspec_matches = 0;
     ++    int ps_i;
     ++    char *norm_pathspec = NULL;
     ++
     ++    /* Only consider if path is a directory */
     ++    if (lstat(path, &st) || !S_ISDIR(st.st_mode))
     ++		return 0;
     ++
     ++    /* Check if it's a submodule with ignore=all */
     ++    sub = submodule_from_path(repo, null_oid(the_hash_algo), path);
     ++    if (!sub || !sub->name || !sub->ignore || strcmp(sub->ignore, "all"))
     ++		return 0;
     ++
     ++    trace_printf("ignore=all: %s\n", path);
     ++    trace_printf("pathspec %s\n", (pathspec && pathspec->nr)
     ++									? "has pathspec"
     ++									: "no pathspec");
     ++
     ++    /* Check if submodule path is explicitly mentioned in pathspec */
     ++    if (pathspec) {
     ++		for (ps_i = 0; ps_i < pathspec->nr; ps_i++) {
     ++			const char *m = pathspec->items[ps_i].match;
     ++			if (!m)
     ++				continue;
     ++			norm_pathspec = xstrdup(m);
     ++			strip_dir_trailing_slashes(norm_pathspec);
     ++			if (!strcmp(path, norm_pathspec)) {
     ++				pathspec_matches = 1;
     ++				FREE_AND_NULL(norm_pathspec);
     ++				break;
     ++			}
     ++			FREE_AND_NULL(norm_pathspec);
      +		}
     - 		case DIFF_STATUS_DELETED:
     - 			if (data->flags & ADD_CACHE_IGNORE_REMOVAL)
     - 				break;
     ++    }
     ++
     ++    /* If explicitly matched and forced, allow adding */
     ++    if (pathspec_matches) {
     ++		if (ignored_too && ignored_too > 0) {
     ++			trace_printf("Add submodule due to --force: %s\n", path);
     ++			return 0;
     ++		} else {
     ++			advise_if_enabled(ADVICE_ADD_IGNORED_FILE,
     ++				_("Skipping submodule due to ignore=all: %s\n"
     ++					"Use --force if you really want to add the submodule."), path);
     ++			return 1;
     ++		}
     ++    }
     ++
     ++    /* No explicit pathspec match -> skip silently */
     ++    trace_printf("Pathspec to submodule does not match explicitly: %s\n", path);
     ++    return 1;
     ++}
     ++
     + static void update_callback(struct diff_queue_struct *q,
     +-			    struct diff_options *opt UNUSED, void *cbdata)
     ++							struct diff_options *opt UNUSED, void *cbdata)
     + {
     + 	int i;
     + 	struct update_callback_data *data = cbdata;
     +@@ read-cache.c: static void update_callback(struct diff_queue_struct *q,
     + 		const char *path = p->one->path;
     + 
     + 		if (!data->include_sparse &&
     +-		    !path_in_sparse_checkout(path, data->index))
     ++			!path_in_sparse_checkout(path, data->index))
     + 			continue;
     + 
     + 		switch (fix_unmerged_status(p, data)) {
     + 		default:
     + 			die(_("unexpected diff status %c"), p->status);
     + 		case DIFF_STATUS_MODIFIED:
     +-		case DIFF_STATUS_TYPE_CHANGED: {
     ++		case DIFF_STATUS_TYPE_CHANGED:
     ++			if (skip_submodule(path, data->repo,
     ++								data->pathspec,
     ++								data->ignored_too))
     ++				continue;
     ++
     + 			if (add_file_to_index(data->index, path, data->flags)) {
     + 				if (!(data->flags & ADD_CACHE_IGNORE_ERRORS))
     + 					die(_("updating files failed"));
 3:  399a153b95 ! 3:  d7b97e12d3 tests: add new t2206-add-submodule-ignored.sh to test ignore=all scenario
     @@ Metadata
      Author: Claus Schneider(Eficode) <claus.schneider@eficode.com>
      
       ## Commit message ##
     -    tests: add new t2206-add-submodule-ignored.sh to test ignore=all scenario
     +    tests: t2206-add-submodule-ignored: ignore=all and add --force tests
      
          The tests verify that the submodule behavior is intact and updating the
          config with ignore=all also behaves as intended with configuration in
          .gitmodules and configuration given on the command line.
      
     -    The usage of --include_ignored_submodules is showcased and tested in the
     -    test suite.
     +    The usage of --force is showcased and tested in the test suite.
      
          The test file is added to meson.build for execution.
      
     @@ t/t2206-add-submodule-ignored.sh (new)
      +# This test covers the behavior of "git add", "git status" and "git log" when
      +# dealing with submodules that have the ignore=all setting in
      +# .gitmodules. It ensures that changes in such submodules are
     -+# ignored by default, but can be staged with "git add --include-ignored-submodules".
     ++# ignored by default, but can be staged with "git add --force".
      +
      +# shellcheck disable=SC1091
      +. ./test-lib.sh
     @@ t/t2206-add-submodule-ignored.sh (new)
      +'
      +
      +#6
     -+# check that 'git add --include-ignored-submodules .' does not stage the change in the submodule
     ++# check that 'git add --force .' does not stage the change in the submodule
      +# and that 'git status' does not show it as modified
     -+test_expect_success 'main: check --include-ignored-submodules add . and status'  '
     ++test_expect_success 'main: check --force add . and status'  '
      +	cd "${base_path}" &&
      +	cd main &&
     -+	GIT_TRACE=1 git add --include-ignored-submodules . &&
     ++	GIT_TRACE=1 git add --force . &&
      +	! git status --porcelain | grep "^M  sub$" &&
      +	echo
      +'
     @@ t/t2206-add-submodule-ignored.sh (new)
      +test_expect_success 'main: check _add sub_ and status'  '
      +	cd "${base_path}" &&
      +	cd main &&
     -+	GIT_TRACE=1 git add sub | grep "Skipping submodule due to ignore=all: sub" &&
     ++	GIT_TRACE=1 git add sub 2>&1 | grep "Skipping submodule due to ignore=all: sub" &&
      +	! git status --porcelain | grep "^M  sub$" &&
      +	echo
      +'
      +
      +#8
     -+# check that 'git add --include-ignored-submodules sub' does stage the change in the submodule
     -+# check that 'git add --include-ignored-submodules ./sub/' does stage the change in the submodule
     ++# check that 'git add --force sub' does stage the change in the submodule
     ++# check that 'git add --force ./sub/' does stage the change in the submodule
      +# and that 'git status --porcelain' does show it as modified
      +# commit it..
      +# check that 'git log --ignore-submodules=none' shows the submodule change
     @@ t/t2206-add-submodule-ignored.sh (new)
      +test_expect_success 'main: check force add sub and ./sub/ and status'  '
      +	cd "${base_path}" &&
      +	cd main &&
     -+	echo "Adding with --include-ignored-submodules should work: git add --include-ignored-submodules sub" &&
     -+	GIT_TRACE=1 git add --include-ignored-submodules sub &&
     ++	echo "Adding with --force should work: git add --force sub" &&
     ++	GIT_TRACE=1 git add --force sub &&
      +	git status --porcelain | grep "^M  sub$" &&
      +	git restore --staged sub &&
      +	! git status --porcelain | grep "^M  sub$" &&
     -+	echo "Adding with --include-ignored-submodules should work: git add --include-ignored-submodules ./sub/" &&
     -+	GIT_TRACE=1 git add --include-ignored-submodules ./sub/ &&
     ++	echo "Adding with --force should work: git add --force ./sub/" &&
     ++	GIT_TRACE=1 git add --force ./sub/ &&
      +	git status --porcelain | grep "^M  sub$" &&
      +	git commit -m "update submodule pointer" &&
      +	! git status --porcelain | grep "^ M sub$" &&
 4:  93c95954f1 ! 4:  6e44ab6804 tests: fix existing tests when add an ignore=all submodule
     @@ Metadata
       ## Commit message ##
          tests: fix existing tests when add an ignore=all submodule
      
     -    There are tests that rely on "git add <submodule>" to add updates in the
     -    parent repository. A new option --include-ignored-submodules is introduced
     -    as it is now needed with this enhancement.
     +    There are tests that rely on "git add <submodule>" to update the in the
     +    reference in the parent repository which have been updated to use the
     +    --force option.
      
          Updated tests:
          - t1013-read-tree-submodule.sh ( fixed in: t/lib-submodule-update.sh )
     @@ t/lib-submodule-update.sh: create_lib_submodule_repo () {
       			git push origin modifications
       		) &&
      -		git add sub1 &&
     -+		git add --include-ignored-submodules sub1 &&
     ++		git add --force sub1 &&
       		git commit -m "Modify sub1" &&
       
       		git checkout -b add_nested_sub modify_sub1 &&
     @@ t/lib-submodule-update.sh: create_lib_submodule_repo () {
       		git -C sub1 submodule add --branch no_submodule ../submodule_update_sub2 sub2 &&
       		git -C sub1 commit -a -m "add a nested submodule" &&
      -		git add sub1 &&
     -+		git add --include-ignored-submodules sub1 &&
     ++		git add --force sub1 &&
       		git commit -a -m "update submodule, that updates a nested submodule" &&
       		git checkout -b modify_sub1_recursively &&
       		git -C sub1 checkout -b modify_sub1_recursively &&
     @@ t/lib-submodule-update.sh: create_lib_submodule_repo () {
       		git -C sub1 add sub2 &&
       		git -C sub1 commit -m "update nested sub" &&
      -		git add sub1 &&
     -+		git add --include-ignored-submodules sub1 &&
     ++		git add --force sub1 &&
       		git commit -m "update sub1, that updates nested sub" &&
       		git -C sub1 push origin modify_sub1_recursively &&
       		git -C sub1/sub2 push origin modify_sub1_recursively &&
     @@ t/t7508-status.sh: test_expect_success 'git commit will commit a staged but igno
       test_expect_success 'git commit --dry-run will show a staged but ignored submodule' '
       	git reset HEAD^ &&
      -	git add sm &&
     -+	git add --include-ignored-submodules sm &&
     ++	git add --force sm &&
       	cat >expect << EOF &&
       On branch main
       Your branch and '\''upstream'\'' have diverged,
 5:  ee84190cd8 ! 5:  37fe7956e0 Documentation: add --include_ignored_submodules + ignore=all config
     @@ Metadata
      Author: Claus Schneider(Eficode) <claus.schneider@eficode.com>
      
       ## Commit message ##
     -    Documentation: add --include_ignored_submodules + ignore=all config
     +    Documentation: update add --force option + ignore=all config
      
     -    - git-add.adoc: Add new documentation for --include_ignored_submodules
     -      option to supress ignore=all and new submodule functionality of not
     -      adding a ignore=all submodule by default.
     +    - git-add.adoc: Update the --force documentation for submodule behaviour
     +      to be added even the given configuration ignore=all.
          - gitmodules.adoc and config/submodule.adoc: The submodule config
     -      ignore=all now need --include_ignored_submodules in order to update
     -      the index.
     +      ignore=all now need --force in order to update the index.
      
          Signed-off-by: Claus Schneider(Eficode) <claus.schneider@eficode.com>
      
     - ## .devcontainer/Dockerfile (new) ##
     -@@
     -+FROM ubuntu:latest
     -+
     -+ARG USER_ID
     -+ARG GROUP_ID
     -+
     -+ENV DEBIAN_FRONTEND=noninteractive
     -+ENV TZ=Europe/Copenhagen
     -+
     -+RUN apt-get update \
     -+    && \
     -+    apt-get install -y \
     -+        sudo \
     -+        build-essential \
     -+        libcurl4-gnutls-dev \
     -+        libexpat1-dev \
     -+        gettext \
     -+        libz-dev \
     -+        libssl-dev \
     -+        asciidoc \
     -+        xmlto \
     -+        docbook-xsl \
     -+        \
     -+        tzdata \
     -+        git \
     -+        coccinelle \
     -+    && \
     -+    ln -fs /usr/share/zoneinfo/$TZ /etc/localtime \
     -+    && \
     -+    dpkg-reconfigure --frontend noninteractive tzdata
     -+
     -+RUN  apt-get update && apt-get install -y autoconf
     -+
     -+RUN addgroup -gid 1001 gituser
     -+RUN adduser --disabled-password -u 1001 -gid 1001 gituser
     -+RUN usermod -aG sudo gituser
     -+RUN echo 'gituser ALL=(ALL) NOPASSWD:ALL' > /etc/sudoers.d/010-gituser
     -+RUN chmod 0440 /etc/sudoers.d/010-gituser
     -+
     -+USER 1001
     -+
     -+#WORKDIR /home/gituser/git-src/
     -+
     -+#RUN  make configure
     -+#RUN ./configure --prefix=${HOME}/.local/
     -+
     -+#RUN make -j$(nproc) gitweb || make gitweb 
     -+#RUN make install-gitweb
     -+
     -+#RUN make -j$(nproc) || make
     -+#RUN make -j$(nproc) gitweb || make gitweb 
     -+#RUN make install-gitweb
     -+#RUN make -j$(nproc) NO_PERL=YesPlease install || make NO_PERL=YesPlease install
     -+#RUN make install
     -+
     -+
     -+RUN mkdir -p  ${HOME}/.local/
     -+#RUN ls -la ${HOME}/.local/bin
     -+#ENV PATH="/home/gituser/.local/bin:${PATH}"
     -+#RUN ls -l $HOME/.local/bin
     -+#RUN echo $PATH $HOME 
     -+
     -+#RUN git --version
     -+#RUN which git 
     -+
     -+RUN git config --global user.email "gituser@example.com"
     -+RUN git config --global user.name "Git User"
     -+
     -+#WORKDIR /home/gituser/git-test/
     -+
     -+#CMD [ "git" ]
     -
     - ## .devcontainer/Dockerfile.standalone (new) ##
     -@@
     -+FROM ubuntu:latest
     -+
     -+ARG USER_ID
     -+ARG GROUP_ID
     -+
     -+ENV DEBIAN_FRONTEND=noninteractive
     -+ENV TZ=Europe/Copenhagen
     -+
     -+RUN apt-get update \
     -+    && \
     -+    apt-get install -y \
     -+        build-essential \
     -+        libcurl4-gnutls-dev \
     -+        libexpat1-dev \
     -+        gettext \
     -+        libz-dev \
     -+        libssl-dev \
     -+        asciidoc \
     -+        xmlto \
     -+        docbook-xsl \
     -+        \
     -+        tzdata \
     -+        \
     -+        nano \
     -+        vim \
     -+    && \
     -+    ln -fs /usr/share/zoneinfo/$TZ /etc/localtime \
     -+    && \
     -+    dpkg-reconfigure --frontend noninteractive tzdata
     -+
     -+RUN  apt-get update && apt-get install -y autoconf
     -+
     -+RUN addgroup -gid ${GROUP_ID} gituser
     -+RUN adduser --disabled-password -u ${USER_ID} -gid ${GROUP_ID} gituser
     -+
     -+
     -+COPY --chown=${USER_ID}:${GROUP_ID} ./git /home/gituser/git-src/
     -+
     -+USER ${USER_ID}
     -+
     -+WORKDIR /home/gituser/git-src/
     -+
     -+RUN  make configure
     -+RUN ./configure --prefix=${HOME}/.local/
     -+
     -+#RUN make -j$(nproc) gitweb || make gitweb 
     -+#RUN make install-gitweb
     -+
     -+#RUN make -j$(nproc) || make
     -+#RUN make -j$(nproc) gitweb || make gitweb 
     -+#RUN make install-gitweb
     -+RUN make -j$(nproc) NO_PERL=YesPlease install || make NO_PERL=YesPlease install
     -+RUN make install
     -+
     -+WORKDIR /home/gituser/git-src/t
     -+RUN ./t2206-add-submodule-ignored.sh -v
     -+
     -+RUN ls -la ${HOME}/.local/
     -+RUN ls -la ${HOME}/.local/bin
     -+ENV PATH="/home/gituser/.local/bin:${PATH}"
     -+RUN ls -l $HOME/.local/bin
     -+RUN echo $PATH $HOME 
     -+
     -+RUN git --version
     -+RUN which git 
     -+
     -+RUN git config --global user.email "gituser@example.com"
     -+RUN git config --global user.name "Git User"
     -+
     -+WORKDIR /home/gituser/git-src/t
     -+RUN pwd && ls -la 
     -+RUN ./t2206-add-submodule-ignored.sh -v
     -+
     -+WORKDIR /home/gituser/git-test/
     -+
     -+CMD [ "git" ]
     -
     - ## .devcontainer/devcontainer.json (new) ##
     -@@
     -+{
     -+  "name": "Git Dev Container",
     -+  "build": {
     -+    "dockerfile": "Dockerfile",
     -+    "context": "",
     -+    "args": {
     -+      "user_id": "1001",
     -+      "group_id": "1001"
     -+    }
     -+  },
     -+  "customizations": {
     -+    "vscode": {
     -+      "settings": {
     -+        "terminal.integrated.shell.linux": "/bin/bash"
     -+      }
     -+    }
     -+  },
     -+  "remoteUser": "gituser",
     -+  "features": {},
     -+  "mounts": [
     -+    "source=${localWorkspaceFolder}/,target=/home/gitusers/git-src,type=bind,consistency=cached",
     -+    "source=${localWorkspaceFolder}/,target=/home/gitusers/git-test,type=bind,consistency=cached"
     -+  ],
     -+  "postCreateCommand": "echo"
     -+}
     -
       ## Documentation/config/submodule.adoc ##
      @@ Documentation/config/submodule.adoc: submodule.<name>.fetchRecurseSubmodules::
       
     @@ Documentation/config/submodule.adoc: submodule.<name>.fetchRecurseSubmodules::
      -	commit when it has been staged), "dirty" will ignore all changes
      -	to the submodule's work tree and
      +	a submodule as modified.
     -+	Set to "all" will never considered the submodule modified. It can
     -+	nevertheless be staged using the option --include_ignored_submodules and
     -+	it will then show up in the output of status.
     ++	Set to "all" will never consider the submodule modified. It can
     ++	nevertheless be staged using the option --force and it will then show up
     ++	in the output of status.
      +	Set to "dirty" will ignore all changes to the submodule's work tree and
       	takes only differences between the HEAD of the submodule and the commit
       	recorded in the superproject into account. "untracked" will additionally
     @@ Documentation/config/submodule.adoc: submodule.<name>.fetchRecurseSubmodules::
      
       ## Documentation/git-add.adoc ##
      @@ Documentation/git-add.adoc: in linkgit:gitglossary[7].
     + 
     + `-f`::
       `--force`::
     - 	Allow adding otherwise ignored files.
     +-	Allow adding otherwise ignored files.
     ++	Allow adding otherwise ignored files. The option is also used when
     ++	`submodule.<name>.ignore=all` is set, but you want to stage an
     ++	update of the submodule. The `path` to the submodule must be explicitly
     ++	specified.
       
     -+`--include_ignored_submodules`::
     -+	The option is also used when `submodule.<name>.ignore=all`
     -+	is set, but you want to stage an update of the submodule. The
     -+	`path` to the submodule must be explicitly specified.
     -+
       `--sparse`::
       	Allow updating index entries outside of the sparse-checkout cone.
     - 	Normally, `git add` refuses to update index entries whose paths do
      
       ## Documentation/gitmodules.adoc ##
      @@ Documentation/gitmodules.adoc: submodule.<name>.ignore::
     @@ Documentation/gitmodules.adoc: submodule.<name>.ignore::
       	    nonetheless show up in the output of status and commit when it has
      -	    been staged).
      +	    been staged). Add `(new commits)` can be overruled using the
     -+	    `git add --include_ignored_submodules <submodule.path>` 
     -+		The setting affects `status`, `update-index`, `diff` and `log`(due 
     ++	    `git add --force <submodule.path>`.
     ++		The setting affects `status`, `update-index`, `diff` and `log`(due
      +		to underlaying `diff`).
       
       	dirty;; All changes to the submodule's work tree will be ignored, only
-- 
gitgitgadget
Claus Schneider(Eficode) via GitGitGadget· Jan 14, 2026, 07:47 UTC · re: Claus Schneider via GitGitGadget · lore

[PATCH v3 1/5] read-cache: update add_files_to_cache take param ignored_too

From: "Claus Schneider(Eficode)" <claus.schneider@eficode.com>

The ignored_too parameter is added to the function add_files_to_cache for usage of explicit updating the index for the updated submodule using the explicit patchspec to the submodule.

Signed-off-by: Claus Schneider(Eficode) <claus.schneider@eficode.com>
---
 builtin/add.c      |  2 +-
 builtin/checkout.c |  2 +-
 builtin/commit.c   |  2 +-
 read-cache-ll.h    |  2 +-
 read-cache.c       | 10 ++++++++--
 5 files changed, 12 insertions(+), 6 deletions(-)
Show changes to 5 files +12 −6

builtin/add.c, builtin/checkout.c, builtin/commit.c, read-cache-ll.h, read-cache.c

diff --git a/builtin/add.c b/builtin/add.c
index 32709794b3..eef4959ee3 100644
--- a/builtin/add.c
+++ b/builtin/add.c
@@ -584,7 +584,7 @@ int cmd_add(int argc,
 	else
 		exit_status |= add_files_to_cache(repo, prefix,
 						  &pathspec, ps_matched,
-						  include_sparse, flags);
+						  include_sparse, flags, ignored_too);
 
 	if (take_worktree_changes && !add_renormalize && !ignore_add_errors &&
 	    report_path_error(ps_matched, &pathspec))
diff --git a/builtin/checkout.c b/builtin/checkout.c
index f9453473fe..88d6a68022 100644
--- a/builtin/checkout.c
+++ b/builtin/checkout.c
@@ -899,7 +899,7 @@ static int merge_working_tree(const struct checkout_opts *opts,
 			 */
 
 			add_files_to_cache(the_repository, NULL, NULL, NULL, 0,
-					   0);
+					0, 0);
 			init_ui_merge_options(&o, the_repository);
 			o.verbosity = 0;
 			work = write_in_core_index_as_tree(the_repository);
diff --git a/builtin/commit.c b/builtin/commit.c
index 0243f17d53..1a00642090 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -455,7 +455,7 @@ static const char *prepare_index(const char **argv, const char *prefix,
 		repo_hold_locked_index(the_repository, &index_lock,
 				       LOCK_DIE_ON_ERROR);
 		add_files_to_cache(the_repository, also ? prefix : NULL,
-				   &pathspec, ps_matched, 0, 0);
+				   &pathspec, ps_matched, 0, 0, 0 );
 		if (!all && report_path_error(ps_matched, &pathspec))
 			exit(128);
 
diff --git a/read-cache-ll.h b/read-cache-ll.h
index 71b49d9af4..2c8b4b21b1 100644
--- a/read-cache-ll.h
+++ b/read-cache-ll.h
@@ -481,7 +481,7 @@ int cmp_cache_name_compare(const void *a_, const void *b_);
 
 int add_files_to_cache(struct repository *repo, const char *prefix,
 		       const struct pathspec *pathspec, char *ps_matched,
-		       int include_sparse, int flags);
+		       int include_sparse, int flags, int ignored_too );
 
 void overlay_tree_on_index(struct index_state *istate,
 			   const char *tree_name, const char *prefix);
diff --git a/read-cache.c b/read-cache.c
index 032480d0c7..0f4981d79f 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -3881,9 +3881,12 @@ void overlay_tree_on_index(struct index_state *istate,
 
 struct update_callback_data {
 	struct index_state *index;
+	struct repository *repo;
+	struct pathspec *pathspec;
 	int include_sparse;
 	int flags;
 	int add_errors;
+	int ignored_too;
 };
 
 static int fix_unmerged_status(struct diff_filepair *p,
@@ -3925,7 +3928,7 @@ static void update_callback(struct diff_queue_struct *q,
 		default:
 			die(_("unexpected diff status %c"), p->status);
 		case DIFF_STATUS_MODIFIED:
-		case DIFF_STATUS_TYPE_CHANGED:
+		case DIFF_STATUS_TYPE_CHANGED: {
 			if (add_file_to_index(data->index, path, data->flags)) {
 				if (!(data->flags & ADD_CACHE_IGNORE_ERRORS))
 					die(_("updating files failed"));
@@ -3946,7 +3949,7 @@ static void update_callback(struct diff_queue_struct *q,
 
 int add_files_to_cache(struct repository *repo, const char *prefix,
 		       const struct pathspec *pathspec, char *ps_matched,
-		       int include_sparse, int flags)
+		       int include_sparse, int flags, int ignored_too )
 {
 	struct odb_transaction *transaction;
 	struct update_callback_data data;
@@ -3956,6 +3959,9 @@ int add_files_to_cache(struct repository *repo, const char *prefix,
 	data.index = repo->index;
 	data.include_sparse = include_sparse;
 	data.flags = flags;
+	data.repo = repo;
+	data.ignored_too = ignored_too;
+	data.pathspec = (struct pathspec *)pathspec;
 
 	repo_init_revisions(repo, &rev, prefix);
 	setup_revisions(0, NULL, &rev, NULL);
-- 
gitgitgadget
Claus Schneider(Eficode) via GitGitGadget· Jan 14, 2026, 07:47 UTC · re: Claus Schneider via GitGitGadget · lore

[PATCH v3 2/5] read-cache: submodule add need --force given ignore=all configuration

From: "Claus Schneider(Eficode)" <claus.schneider@eficode.com>

Submodules configured with ignore=all are now skipped during add operations unless overridden by --force and the submodule path is explicitly specified.

A message is printed (like ignored files) guiding the user to use the --force flag if the user has explicitely want to update the submodule reference.

The reason for the change is support submodule branch tracking or similar and git status states nothing and git add should not add either as a default behaviour. The workflow is more logic and similar to regular ignored files even the submodule is already tracked.

The change opens up a lot of possibilities for submodules to be used more freely and simular to the repo tool. A submodule can be added for many more reason and loosely coupled dependencies to the super repo which often gives the friction of handle the explicit commits and updates without the need for tracking the submodule sha1 by sha1.

Signed-off-by: Claus Schneider(Eficode) <claus.schneider@eficode.com>
---
 read-cache.c | 74 +++++++++++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 71 insertions(+), 3 deletions(-)
Show changes to read-cache.c +71 −3
diff --git a/read-cache.c b/read-cache.c
index 0f4981d79f..cc79b25f43 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -47,6 +47,9 @@
 #include "csum-file.h"
 #include "promisor-remote.h"
 #include "hook.h"
+#include "submodule.h"
+#include "submodule-config.h"
+#include "advice.h"
 
 /* Mask for the name length in ce_flags in the on-disk index */
 
@@ -3910,8 +3913,68 @@ static int fix_unmerged_status(struct diff_filepair *p,
 		return DIFF_STATUS_MODIFIED;
 }
 
+static int skip_submodule(const char *path,
+						struct repository *repo,
+						struct pathspec *pathspec,
+						int ignored_too)
+{
+    struct stat st;
+    const struct submodule *sub;
+    int pathspec_matches = 0;
+    int ps_i;
+    char *norm_pathspec = NULL;
+
+    /* Only consider if path is a directory */
+    if (lstat(path, &st) || !S_ISDIR(st.st_mode))
+		return 0;
+
+    /* Check if it's a submodule with ignore=all */
+    sub = submodule_from_path(repo, null_oid(the_hash_algo), path);
+    if (!sub || !sub->name || !sub->ignore || strcmp(sub->ignore, "all"))
+		return 0;
+
+    trace_printf("ignore=all: %s\n", path);
+    trace_printf("pathspec %s\n", (pathspec && pathspec->nr)
+									? "has pathspec"
+									: "no pathspec");
+
+    /* Check if submodule path is explicitly mentioned in pathspec */
+    if (pathspec) {
+		for (ps_i = 0; ps_i < pathspec->nr; ps_i++) {
+			const char *m = pathspec->items[ps_i].match;
+			if (!m)
+				continue;
+			norm_pathspec = xstrdup(m);
+			strip_dir_trailing_slashes(norm_pathspec);
+			if (!strcmp(path, norm_pathspec)) {
+				pathspec_matches = 1;
+				FREE_AND_NULL(norm_pathspec);
+				break;
+			}
+			FREE_AND_NULL(norm_pathspec);
+		}
+    }
+
+    /* If explicitly matched and forced, allow adding */
+    if (pathspec_matches) {
+		if (ignored_too && ignored_too > 0) {
+			trace_printf("Add submodule due to --force: %s\n", path);
+			return 0;
+		} else {
+			advise_if_enabled(ADVICE_ADD_IGNORED_FILE,
+				_("Skipping submodule due to ignore=all: %s\n"
+					"Use --force if you really want to add the submodule."), path);
+			return 1;
+		}
+    }
+
+    /* No explicit pathspec match -> skip silently */
+    trace_printf("Pathspec to submodule does not match explicitly: %s\n", path);
+    return 1;
+}
+
 static void update_callback(struct diff_queue_struct *q,
-			    struct diff_options *opt UNUSED, void *cbdata)
+							struct diff_options *opt UNUSED, void *cbdata)
 {
 	int i;
 	struct update_callback_data *data = cbdata;
@@ -3921,14 +3984,19 @@ static void update_callback(struct diff_queue_struct *q,
 		const char *path = p->one->path;
 
 		if (!data->include_sparse &&
-		    !path_in_sparse_checkout(path, data->index))
+			!path_in_sparse_checkout(path, data->index))
 			continue;
 
 		switch (fix_unmerged_status(p, data)) {
 		default:
 			die(_("unexpected diff status %c"), p->status);
 		case DIFF_STATUS_MODIFIED:
-		case DIFF_STATUS_TYPE_CHANGED: {
+		case DIFF_STATUS_TYPE_CHANGED:
+			if (skip_submodule(path, data->repo,
+								data->pathspec,
+								data->ignored_too))
+				continue;
+
 			if (add_file_to_index(data->index, path, data->flags)) {
 				if (!(data->flags & ADD_CACHE_IGNORE_ERRORS))
 					die(_("updating files failed"));
-- 
gitgitgadget
Claus Schneider(Eficode) via GitGitGadget· Jan 14, 2026, 07:47 UTC · re: Claus Schneider via GitGitGadget · lore

[PATCH v3 3/5] tests: t2206-add-submodule-ignored: ignore=all and add --force tests

From: "Claus Schneider(Eficode)" <claus.schneider@eficode.com>

The tests verify that the submodule behavior is intact and updating the config with ignore=all also behaves as intended with configuration in .gitmodules and configuration given on the command line.

The usage of --force is showcased and tested in the test suite.
The test file is added to meson.build for execution.
Signed-off-by: Claus Schneider(Eficode) <claus.schneider@eficode.com>
---
 t/meson.build                    |   1 +
 t/t2206-add-submodule-ignored.sh | 134 +++++++++++++++++++++++++++++++
 2 files changed, 135 insertions(+)
 create mode 100755 t/t2206-add-submodule-ignored.sh
Show changes to 2 files +135 −0

t/meson.build, t/t2206-add-submodule-ignored.sh

diff --git a/t/meson.build b/t/meson.build
index a5531df415..a7d3e3e0a2 100644
--- a/t/meson.build
+++ b/t/meson.build
@@ -290,6 +290,7 @@ integration_tests = [
   't2203-add-intent.sh',
   't2204-add-ignored.sh',
   't2205-add-worktree-config.sh',
+  't2206-add-submodule-ignored.sh',
   't2300-cd-to-toplevel.sh',
   't2400-worktree-add.sh',
   't2401-worktree-prune.sh',
diff --git a/t/t2206-add-submodule-ignored.sh b/t/t2206-add-submodule-ignored.sh
new file mode 100755
index 0000000000..e581e87ab2
--- /dev/null
+++ b/t/t2206-add-submodule-ignored.sh
@@ -0,0 +1,134 @@
+#!/bin/sh
+# shellcheck disable=SC2016
+
+# shellcheck disable=SC2034
+test_description='git add respects submodule ignore=all and explicit pathspec'
+
+# This test covers the behavior of "git add", "git status" and "git log" when
+# dealing with submodules that have the ignore=all setting in
+# .gitmodules. It ensures that changes in such submodules are
+# ignored by default, but can be staged with "git add --force".
+
+# shellcheck disable=SC1091
+. ./test-lib.sh
+
+GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
+export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
+
+base_path=$(pwd -P)
+
+#1
+test_expect_success 'setup: create origin repos'  '
+	cd "${base_path}" &&
+	git config --global protocol.file.allow always &&
+	git init sub &&
+		pwd &&
+		cd sub &&
+		test_commit sub_file1 &&
+		git tag v1.0 &&
+		test_commit sub_file2 &&
+		git tag v2.0 &&
+		test_commit sub_file3 &&
+		git tag v3.0 &&
+	cd "${base_path}" &&
+	git init main &&
+		cd main &&
+		test_commit first &&
+	cd "${base_path}"
+'
+#2
+# add submodule with default config (ignore=none) and
+# check log that is contains a path entry for the submodule 'sub'
+# change the commit in the submodule and check that 'git status' shows it as modified
+test_expect_success 'main: add submodule with default config'  '
+	cd "${base_path}" &&
+	cd main &&
+	git submodule add ../sub &&
+	git commit -m "add submodule" &&
+	git log --oneline --name-only | grep "^sub$" &&
+	git -C sub reset --hard v2.0 &&
+	git status --porcelain | grep "^ M sub$" &&
+	echo
+'
+#3
+# change the submodule config to ignore=all and check that status and log do not show changes
+test_expect_success 'main: submodule config ignore=all'  '
+	cd "${base_path}" &&
+	cd main &&
+	git config -f .gitmodules submodule.sub.ignore all &&
+	GIT_TRACE=1 git add . &&
+	git commit -m "update submodule config sub.ignore all" &&
+	! git status --porcelain | grep "^.*$" &&
+	! git log --oneline --name-only | grep "^sub$" &&
+	echo
+'
+#4
+# change the commit in the submodule and check that 'git status' does not show it as modified
+# but 'git status --ignore-submodules=none' does show it as modified
+test_expect_success 'sub: change to different sha1 and check status in main'  '
+	cd "${base_path}" &&
+	cd main &&
+	git -C sub reset --hard v1.0 &&
+	! git status --porcelain | grep "^ M sub$" &&
+	git status --ignore-submodules=none --porcelain | grep "^ M sub$" &&
+	echo
+'
+
+#5
+# check that normal 'git add' does not stage the change in the submodule
+test_expect_success 'main: check normal add and status'  '
+	cd "${base_path}" &&
+	cd main &&
+	GIT_TRACE=1 git add . &&
+	! git status --porcelain | grep "^ M sub$" &&
+	echo
+'
+
+#6
+# check that 'git add --force .' does not stage the change in the submodule
+# and that 'git status' does not show it as modified
+test_expect_success 'main: check --force add . and status'  '
+	cd "${base_path}" &&
+	cd main &&
+	GIT_TRACE=1 git add --force . &&
+	! git status --porcelain | grep "^M  sub$" &&
+	echo
+'
+
+#7
+# check that 'git add .' does not stage the change in the submodule
+# and that 'git status' does not show it as modified
+test_expect_success 'main: check _add sub_ and status'  '
+	cd "${base_path}" &&
+	cd main &&
+	GIT_TRACE=1 git add sub 2>&1 | grep "Skipping submodule due to ignore=all: sub" &&
+	! git status --porcelain | grep "^M  sub$" &&
+	echo
+'
+
+#8
+# check that 'git add --force sub' does stage the change in the submodule
+# check that 'git add --force ./sub/' does stage the change in the submodule
+# and that 'git status --porcelain' does show it as modified
+# commit it..
+# check that 'git log --ignore-submodules=none' shows the submodule change
+# in the log
+test_expect_success 'main: check force add sub and ./sub/ and status'  '
+	cd "${base_path}" &&
+	cd main &&
+	echo "Adding with --force should work: git add --force sub" &&
+	GIT_TRACE=1 git add --force sub &&
+	git status --porcelain | grep "^M  sub$" &&
+	git restore --staged sub &&
+	! git status --porcelain | grep "^M  sub$" &&
+	echo "Adding with --force should work: git add --force ./sub/" &&
+	GIT_TRACE=1 git add --force ./sub/ &&
+	git status --porcelain | grep "^M  sub$" &&
+	git commit -m "update submodule pointer" &&
+	! git status --porcelain | grep "^ M sub$" &&
+	git log --ignore-submodules=none --name-only --oneline | grep "^sub$" &&
+	echo
+'
+
+test_done
+exit 0
-- 
gitgitgadget
Claus Schneider(Eficode) via GitGitGadget· Jan 14, 2026, 07:47 UTC · re: Claus Schneider via GitGitGadget · lore

[PATCH v3 4/5] tests: fix existing tests when add an ignore=all submodule

From: "Claus Schneider(Eficode)" <claus.schneider@eficode.com>

There are tests that rely on "git add <submodule>" to update the in the reference in the parent repository which have been updated to use the --force option.

Updated tests:
- t1013-read-tree-submodule.sh ( fixed in: t/lib-submodule-update.sh )
- t2013-checkout-submodule.sh ( fixed in: t/lib-submodule-update.sh )
- t7406-submodule-update.sh
- t7508-status.sh
Signed-off-by: Claus Schneider(Eficode) <claus.schneider@eficode.com>
---
 t/lib-submodule-update.sh | 6 +++---
 t/t7508-status.sh         | 2 +-
 2 files changed, 4 insertions(+), 4 deletions(-)
Show changes to 2 files +4 −4

t/lib-submodule-update.sh, t/t7508-status.sh

diff --git a/t/lib-submodule-update.sh b/t/lib-submodule-update.sh
index 36f767cb74..f591de6120 100644
--- a/t/lib-submodule-update.sh
+++ b/t/lib-submodule-update.sh
@@ -95,14 +95,14 @@ create_lib_submodule_repo () {
 			git commit -m "modified file2 and added file3" &&
 			git push origin modifications
 		) &&
-		git add sub1 &&
+		git add --force sub1 &&
 		git commit -m "Modify sub1" &&
 
 		git checkout -b add_nested_sub modify_sub1 &&
 		git -C sub1 checkout -b "add_nested_sub" &&
 		git -C sub1 submodule add --branch no_submodule ../submodule_update_sub2 sub2 &&
 		git -C sub1 commit -a -m "add a nested submodule" &&
-		git add sub1 &&
+		git add --force sub1 &&
 		git commit -a -m "update submodule, that updates a nested submodule" &&
 		git checkout -b modify_sub1_recursively &&
 		git -C sub1 checkout -b modify_sub1_recursively &&
@@ -112,7 +112,7 @@ create_lib_submodule_repo () {
 		git -C sub1/sub2 commit -m "make a change in nested sub" &&
 		git -C sub1 add sub2 &&
 		git -C sub1 commit -m "update nested sub" &&
-		git add sub1 &&
+		git add --force sub1 &&
 		git commit -m "update sub1, that updates nested sub" &&
 		git -C sub1 push origin modify_sub1_recursively &&
 		git -C sub1/sub2 push origin modify_sub1_recursively &&
diff --git a/t/t7508-status.sh b/t/t7508-status.sh
index abad229e9d..a5e21bf8bf 100755
--- a/t/t7508-status.sh
+++ b/t/t7508-status.sh
@@ -1576,7 +1576,7 @@ test_expect_success 'git commit will commit a staged but ignored submodule' '
 
 test_expect_success 'git commit --dry-run will show a staged but ignored submodule' '
 	git reset HEAD^ &&
-	git add sm &&
+	git add --force sm &&
 	cat >expect << EOF &&
 On branch main
 Your branch and '\''upstream'\'' have diverged,
-- 
gitgitgadget
Claus Schneider(Eficode) via GitGitGadget· Jan 14, 2026, 07:47 UTC · re: Claus Schneider via GitGitGadget · lore

[PATCH v3 5/5] Documentation: update add --force option + ignore=all config

From: "Claus Schneider(Eficode)" <claus.schneider@eficode.com>
- git-add.adoc: Update the --force documentation for submodule behaviour
  to be added even the given configuration ignore=all.
- gitmodules.adoc and config/submodule.adoc: The submodule config
  ignore=all now need --force in order to update the index.
Signed-off-by: Claus Schneider(Eficode) <claus.schneider@eficode.com>
---
 Documentation/config/submodule.adoc | 13 +++++++------
 Documentation/git-add.adoc          |  5 ++++-
 Documentation/gitmodules.adoc       |  5 ++++-
 3 files changed, 15 insertions(+), 8 deletions(-)
Show changes to 3 files +15 −8

Documentation/config/submodule.adoc, Documentation/git-add.adoc, Documentation/gitmodules.adoc

diff --git a/Documentation/config/submodule.adoc b/Documentation/config/submodule.adoc
index 0672d99117..250a6133d8 100644
--- a/Documentation/config/submodule.adoc
+++ b/Documentation/config/submodule.adoc
@@ -32,15 +32,16 @@ submodule.<name>.fetchRecurseSubmodules::
 
 submodule.<name>.ignore::
 	Defines under what circumstances "git status" and the diff family show
-	a submodule as modified. When set to "all", it will never be considered
-	modified (but it will nonetheless show up in the output of status and
-	commit when it has been staged), "dirty" will ignore all changes
-	to the submodule's work tree and
+	a submodule as modified.
+	Set to "all" will never consider the submodule modified. It can
+	nevertheless be staged using the option --force and it will then show up
+	in the output of status.
+	Set to "dirty" will ignore all changes to the submodule's work tree and
 	takes only differences between the HEAD of the submodule and the commit
 	recorded in the superproject into account. "untracked" will additionally
 	let submodules with modified tracked files in their work tree show up.
-	Using "none" (the default when this option is not set) also shows
-	submodules that have untracked files in their work tree as changed.
+	Set to "none"(default) It is also shows submodules that have untracked
+	files in their work tree as changed.
 	This setting overrides any setting made in .gitmodules for this submodule,
 	both settings can be overridden on the command line by using the
 	"--ignore-submodules" option. The 'git submodule' commands are not
diff --git a/Documentation/git-add.adoc b/Documentation/git-add.adoc
index 6192daeb03..941135dc63 100644
--- a/Documentation/git-add.adoc
+++ b/Documentation/git-add.adoc
@@ -75,7 +75,10 @@ in linkgit:gitglossary[7].
 
 `-f`::
 `--force`::
-	Allow adding otherwise ignored files.
+	Allow adding otherwise ignored files. The option is also used when
+	`submodule.<name>.ignore=all` is set, but you want to stage an
+	update of the submodule. The `path` to the submodule must be explicitly
+	specified.
 
 `--sparse`::
 	Allow updating index entries outside of the sparse-checkout cone.
diff --git a/Documentation/gitmodules.adoc b/Documentation/gitmodules.adoc
index d9bec8b187..3792da96aa 100644
--- a/Documentation/gitmodules.adoc
+++ b/Documentation/gitmodules.adoc
@@ -70,7 +70,10 @@ submodule.<name>.ignore::
 --
 	all;; The submodule will never be considered modified (but will
 	    nonetheless show up in the output of status and commit when it has
-	    been staged).
+	    been staged). Add `(new commits)` can be overruled using the
+	    `git add --force <submodule.path>`.
+		The setting affects `status`, `update-index`, `diff` and `log`(due
+		to underlaying `diff`).
 
 	dirty;; All changes to the submodule's work tree will be ignored, only
 	    committed differences between the `HEAD` of the submodule and its
-- 
gitgitgadget
Ben Knoble· Jan 14, 2026, 17:53 UTC · re: Claus Schneider(Eficode) via GitGitGadget · lore

Re: [PATCH v3 5/5] Documentation: update add --force option + ignore=all config

Show 30 quoted lines
> Le 14 janv. 2026 à 02:48, Claus Schneider(Eficode) via GitGitGadget <gitgitgadget@gmail.com> a écrit :
> 
> From: "Claus Schneider(Eficode)" <claus.schneider@eficode.com>
> 
> - git-add.adoc: Update the --force documentation for submodule behaviour
>  to be added even the given configuration ignore=all.
> - gitmodules.adoc and config/submodule.adoc: The submodule config
>  ignore=all now need --force in order to update the index.
> 
> Signed-off-by: Claus Schneider(Eficode) <claus.schneider@eficode.com>
> ---
> Documentation/config/submodule.adoc | 13 +++++++------
> Documentation/git-add.adoc          |  5 ++++-
> Documentation/gitmodules.adoc       |  5 ++++-
> 3 files changed, 15 insertions(+), 8 deletions(-)
> 
> diff --git a/Documentation/config/submodule.adoc b/Documentation/config/submodule.adoc
> index 0672d99117..250a6133d8 100644
> --- a/Documentation/config/submodule.adoc
> +++ b/Documentation/config/submodule.adoc
> @@ -32,15 +32,16 @@ submodule.<name>.fetchRecurseSubmodules::
> 
> submodule.<name>.ignore::
>    Defines under what circumstances "git status" and the diff family show
> -    a submodule as modified. When set to "all", it will never be considered
> -    modified (but it will nonetheless show up in the output of status and
> -    commit when it has been staged), "dirty" will ignore all changes
> -    to the submodule's work tree and
> +    a submodule as modified.
> +    Set to "all" will never consider the
Throughout this patch, missing “When set to…” for idiomatic English. 
Show 49 quoted lines
> submodule modified. It can
> +    nevertheless be staged using the option --force and it will then show up
> +    in the output of status.
> +    Set to "dirty" will ignore all changes to the submodule's work tree and
>    takes only differences between the HEAD of the submodule and the commit
>    recorded in the superproject into account. "untracked" will additionally
>    let submodules with modified tracked files in their work tree show up.
> -    Using "none" (the default when this option is not set) also shows
> -    submodules that have untracked files in their work tree as changed.
> +    Set to "none"(default) It is also shows submodules that have untracked
> +    files in their work tree as changed.
>    This setting overrides any setting made in .gitmodules for this submodule,
>    both settings can be overridden on the command line by using the
>    "--ignore-submodules" option. The 'git submodule' commands are not
> diff --git a/Documentation/git-add.adoc b/Documentation/git-add.adoc
> index 6192daeb03..941135dc63 100644
> --- a/Documentation/git-add.adoc
> +++ b/Documentation/git-add.adoc
> @@ -75,7 +75,10 @@ in linkgit:gitglossary[7].
> 
> `-f`::
> `--force`::
> -    Allow adding otherwise ignored files.
> +    Allow adding otherwise ignored files. The option is also used when
> +    `submodule.<name>.ignore=all` is set, but you want to stage an
> +    update of the submodule. The `path` to the submodule must be explicitly
> +    specified.
> 
> `--sparse`::
>    Allow updating index entries outside of the sparse-checkout cone.
> diff --git a/Documentation/gitmodules.adoc b/Documentation/gitmodules.adoc
> index d9bec8b187..3792da96aa 100644
> --- a/Documentation/gitmodules.adoc
> +++ b/Documentation/gitmodules.adoc
> @@ -70,7 +70,10 @@ submodule.<name>.ignore::
> --
>    all;; The submodule will never be considered modified (but will
>        nonetheless show up in the output of status and commit when it has
> -        been staged).
> +        been staged). Add `(new commits)` can be overruled using the
> +        `git add --force <submodule.path>`.
> +        The setting affects `status`, `update-index`, `diff` and `log`(due
> +        to underlaying `diff`).
> 
>    dirty;; All changes to the submodule's work tree will be ignored, only
>        committed differences between the `HEAD` of the submodule and its
> --
> gitgitgadget
> 
Kristoffer Haugsbakk· Jan 15, 2026, 15:42 UTC · re: Claus Schneider(Eficode) via GitGitGadget · lore

Re: [PATCH v3 2/5] read-cache: submodule add need --force given ignore=all configuration

On Wed, Jan 14, 2026, at 08:47, Claus Schneider(Eficode) via GitGitGadget wrote:
Show 16 quoted lines
> From: "Claus Schneider(Eficode)" <claus.schneider@eficode.com>
>
> Submodules configured with ignore=all are now skipped during add operations
> unless overridden by --force and the submodule path is explicitly specified.
>
> A message is printed (like ignored files) guiding the user to use the
> --force flag if the user has explicitely want to update the submodule
> reference.
>
> The reason for the change is support submodule branch tracking or
> similar and git status states nothing and git add should not add either
> as a default behaviour. The workflow is more logic and similar to regular
> ignored files even the submodule is already tracked.
>
> The change opens up a lot of possibilities for submodules to be used
> more freely and simular to the repo tool. A submodule can be added for many

s/simular/similar/ ? Although the sentence doesn’t quite make sense to me. Well I’m unfamiliar with the domain anyway. ;)

> more reason and loosely coupled dependencies to the super repo which often
s/more reason/more reasons/ ?
> gives the friction of handle the explicit commits and updates without
s/handle/handling/
Show 5 quoted lines
> the need for tracking the submodule sha1 by sha1.
>
> Signed-off-by: Claus Schneider(Eficode) <claus.schneider@eficode.com>
> ---
>[snip]
Claus Schneider· Jan 16, 2026, 15:35 UTC · re: Ben Knoble · lore

Re: [PATCH v3 5/5] Documentation: update add --force option + ignore=all config

Thanks for feedback. Noted and will be fixed as this:

... When set to "all" will never consider the submodule modified. It can nevertheless be staged using the option --force and it will then show up in the output of status. When set to "dirty" will ignore all changes to the submodule's work tree and takes only differences between the HEAD of the submodule and the commit recorded in the superproject into account. "untracked" will additionally let submodules with modified tracked files in their work tree show up. When set to "none"(default) It also show submodules as changed if they have untracked files in their work tree. .. // Claus

On Wed, Jan 14, 2026 at 6:53 PM Ben Knoble <ben.knoble@gmail.com> wrote:
Show 84 quoted lines
>
>
> > Le 14 janv. 2026 à 02:48, Claus Schneider(Eficode) via GitGitGadget <gitgitgadget@gmail.com> a écrit :
> >
> > From: "Claus Schneider(Eficode)" <claus.schneider@eficode.com>
> >
> > - git-add.adoc: Update the --force documentation for submodule behaviour
> >  to be added even the given configuration ignore=all.
> > - gitmodules.adoc and config/submodule.adoc: The submodule config
> >  ignore=all now need --force in order to update the index.
> >
> > Signed-off-by: Claus Schneider(Eficode) <claus.schneider@eficode.com>
> > ---
> > Documentation/config/submodule.adoc | 13 +++++++------
> > Documentation/git-add.adoc          |  5 ++++-
> > Documentation/gitmodules.adoc       |  5 ++++-
> > 3 files changed, 15 insertions(+), 8 deletions(-)
> >
> > diff --git a/Documentation/config/submodule.adoc b/Documentation/config/submodule.adoc
> > index 0672d99117..250a6133d8 100644
> > --- a/Documentation/config/submodule.adoc
> > +++ b/Documentation/config/submodule.adoc
> > @@ -32,15 +32,16 @@ submodule.<name>.fetchRecurseSubmodules::
> >
> > submodule.<name>.ignore::
> >    Defines under what circumstances "git status" and the diff family show
> > -    a submodule as modified. When set to "all", it will never be considered
> > -    modified (but it will nonetheless show up in the output of status and
> > -    commit when it has been staged), "dirty" will ignore all changes
> > -    to the submodule's work tree and
> > +    a submodule as modified.
> > +    Set to "all" will never consider the
>
> Throughout this patch, missing “When set to…” for idiomatic English.
>
> > submodule modified. It can
> > +    nevertheless be staged using the option --force and it will then show up
> > +    in the output of status.
> > +    Set to "dirty" will ignore all changes to the submodule's work tree and
> >    takes only differences between the HEAD of the submodule and the commit
> >    recorded in the superproject into account. "untracked" will additionally
> >    let submodules with modified tracked files in their work tree show up.
> > -    Using "none" (the default when this option is not set) also shows
> > -    submodules that have untracked files in their work tree as changed.
> > +    Set to "none"(default) It is also shows submodules that have untracked
> > +    files in their work tree as changed.
> >    This setting overrides any setting made in .gitmodules for this submodule,
> >    both settings can be overridden on the command line by using the
> >    "--ignore-submodules" option. The 'git submodule' commands are not
> > diff --git a/Documentation/git-add.adoc b/Documentation/git-add.adoc
> > index 6192daeb03..941135dc63 100644
> > --- a/Documentation/git-add.adoc
> > +++ b/Documentation/git-add.adoc
> > @@ -75,7 +75,10 @@ in linkgit:gitglossary[7].
> >
> > `-f`::
> > `--force`::
> > -    Allow adding otherwise ignored files.
> > +    Allow adding otherwise ignored files. The option is also used when
> > +    `submodule.<name>.ignore=all` is set, but you want to stage an
> > +    update of the submodule. The `path` to the submodule must be explicitly
> > +    specified.
> >
> > `--sparse`::
> >    Allow updating index entries outside of the sparse-checkout cone.
> > diff --git a/Documentation/gitmodules.adoc b/Documentation/gitmodules.adoc
> > index d9bec8b187..3792da96aa 100644
> > --- a/Documentation/gitmodules.adoc
> > +++ b/Documentation/gitmodules.adoc
> > @@ -70,7 +70,10 @@ submodule.<name>.ignore::
> > --
> >    all;; The submodule will never be considered modified (but will
> >        nonetheless show up in the output of status and commit when it has
> > -        been staged).
> > +        been staged). Add `(new commits)` can be overruled using the
> > +        `git add --force <submodule.path>`.
> > +        The setting affects `status`, `update-index`, `diff` and `log`(due
> > +        to underlaying `diff`).
> >
> >    dirty;; All changes to the submodule's work tree will be ignored, only
> >        committed differences between the `HEAD` of the submodule and its
> > --
> > gitgitgadget
> >
Claus Schneider· Jan 16, 2026, 16:07 UTC · re: Kristoffer Haugsbakk · lore

Re: [PATCH v3 2/5] read-cache: submodule add need --force given ignore=all configuration

Thanks for feedback. Well noted and it will be reworded like this:

.... A message is printed (like ignored files) guiding the user to use the --force flag if the user explicitly wants to update the submodule reference.

The reason for the change is to support branch tracking in submodules
 with configuration `submdule.<name>.branch` or similar workflows where the
user is not interested in tracking each update of the sha1 in the submdule.
You can additionally set `submodule.<name>.ignore=all` and the
`git status`will state nothing and, with this patch, the `git add`
does not either - as
the default behaviour. This patch changes the workflow to a more logical
behaviour and similar to workflow for ignored files.

The patch gives more scenarios for submodules to be used effectively with less friction similar to the "repo" tool. A submodule can be added for many different reasons than a hard dependency. It can be added as loosely coupled dependencies whereas the user wants the latest based on the configuration `submoule.<name>.branch`, but are not interested to track each commit in the `super-repo`. Currently it gives friction of handling conflicts between branches even the sha1's are fast-forward and the user just wants the latest in any way. A developer can still add a sha1 explicitly to track updates. ...

// Claus

On Thu, Jan 15, 2026 at 4:43 PM Kristoffer Haugsbakk <kristofferhaugsbakk@fastmail.com> wrote:

Show 35 quoted lines
>
> On Wed, Jan 14, 2026, at 08:47, Claus Schneider(Eficode) via GitGitGadget wrote:
> > From: "Claus Schneider(Eficode)" <claus.schneider@eficode.com>
> >
> > Submodules configured with ignore=all are now skipped during add operations
> > unless overridden by --force and the submodule path is explicitly specified.
> >
> > A message is printed (like ignored files) guiding the user to use the
> > --force flag if the user has explicitely want to update the submodule
> > reference.
> >
> > The reason for the change is support submodule branch tracking or
> > similar and git status states nothing and git add should not add either
> > as a default behaviour. The workflow is more logic and similar to regular
> > ignored files even the submodule is already tracked.
> >
> > The change opens up a lot of possibilities for submodules to be used
> > more freely and simular to the repo tool. A submodule can be added for many
>
> s/simular/similar/ ? Although the sentence doesn’t quite make sense to
> me. Well I’m unfamiliar with the domain anyway. ;)
>
> > more reason and loosely coupled dependencies to the super repo which often
>
> s/more reason/more reasons/ ?
>
> > gives the friction of handle the explicit commits and updates without
>
> s/handle/handling/
>
> > the need for tracking the submodule sha1 by sha1.
> >
> > Signed-off-by: Claus Schneider(Eficode) <claus.schneider@eficode.com>
> > ---
> >[snip]
Claus Schneider· Feb 5, 2026, 08:51 UTC · re: Claus Schneider · lore

Re: [PATCH v2 0/5] git-add : Respect submodule ignore=all and only add changes with --force

Hi

I have implemented the --ignore option. I believe it is done. Please review it again for integration to 'next'.

Best regards Claus Schneider

On Fri, Nov 14, 2025 at 2:53 PM Claus Schneider <claus.schneider@eficode.com> wrote:

Show 489 quoted lines
>
> Thanks Junio - well received and noted. I have updated the PR
> description accordingly, but I have not changed the "--force" in the
> description even though I have implemented
> ''--include-ignored-submodules' as Philip had the input not to use
> "--force". He suggested using a new option. Philips comment:
>
> > I'm not convinced that the approach of using "--force" is a good idea as
> > it conflates ignoring changes to tracked paths (which is what
> > submodule.<name>.ignore" does) with ignoring untracked paths (which is
> > what ".gitignore" does). If we're happy to break existing uses that rely
> > on the current behavior then having a new option to override
> > submodule.<name>.ignore strikes me as a better way forward. I don't have
> > much experience of using submodules so I can't comment on whether
> > changing the behavior is a good idea or not.
>
> I think it will be more simple to use the '--force' option though and
> keep the amount of options lower and less to remember. Given your
> comments about more usages of bytes for option also becomes obsolete
> if we stick to "--force". I am happy to do so.
>
> I am investigating your other comments on the patches in the meantime.
>
> On Thu, Nov 13, 2025 at 8:58 PM Junio C Hamano <gitster@pobox.com> wrote:
> >
> > "Claus Schneider via GitGitGadget" <gitgitgadget@gmail.com> writes:
> >
> > > The feature of configuring a submodule to "ignore=all" is nicely respected
> > > in commands "status" and "diff".
> >
> > "nicely respected" is not very informative for those who do not know
> > what the setting does.  Saying something like
> >
> >     "git status" and "git diff" will not report modified submodules
> >     with submodule.<name>.ignore set to "all".
> >
> > would not waste significantly more bytes than what you wrote, and is
> > more helpful.
> >
> > > However the "add" command does not respect
> > > the configuration the same way.
> >
> > Again, "does not respect" and then what?  Running "git add" on a
> > submodule with submodule.<name>.ignore set to "all" does what?
> > Complains that it has changes but because .ignore is set it won't
> > add?  Adds it silently?  Something else?
> >
> > > The behavior is problematic for the logic
> > > between status/diff and add.
> >
> > After this sentence, "because ..." is missing.  Please help readers
> > understand the issue you perceive as problematic more easily.
> >
> > I am guessing that you are assuming that an "add", after "diff" or
> > "status" said there is no change, is expected to be a no-op, but I
> > cannot be sure if that is what you are referring to here with the
> > reason left unsaid like the above.
> >
> > > Secondly it makes it problematic to track
> > > branches in the submodule configuration as developers unintentionally keeps
> > > add submodule updates and get conflicts for no intentional reason. Both adds
> > > unnecessary friction to the usage of submodules.
> > >
> > > The patches implement the same logical behavior for ignore=all submodules as
> > > regular ignored files. The status now does not show any diff - nor will the
> > > add command update the reference submodule reference. If you add the
> > > submodule path which is ignore=all then you are presented with a message
> > > that you need to use the --force option.
> >
> > I vaguely recall that an earlier discussion between you and Phillip
> > were concluding against "--force"?  I personally feel it is in line
> > with "git add foo.o" (when '*.o' is in .gitignore) gets rejected and
> > "git add -f foo.o" is a way to override it, but in the list of
> > patches below, I see --include-ignored-submodules (no, our command
> > line option names do not use underscore for inter-word-gaps), so I
> > suspect the description in the cover letter around here is stale?
> >
> >
> > > The branch=, ignore=all (and
> > > update=none) now works great with update --remote,
> >
> > Again, "great" is not very informative, and as bad as "nicely
> > respected".  Avoid using these adjectives loaded with unnecessary
> > value judgements, and instead trust your readers.  They are
> > intelligent to judge if the updated behaviour is great or not for
> > themselves.  Try to use the same bytes on helping readers understand
> > what actually happens.
> >
> > > but developers does not
> >
> > "do not".
> >
> > > have to consider changes in the updates of the submodule sha1. The
> > > implementation removes a friction of working with submodules and can be used
> > > like the repo tool with branches configured. The submodule status report
> > > could be used for build/release documentation for reproduction of a setup.
> > >
> > > A few tests used the adding of submodules without --force, hence they have
> > > been updated to use the --force option.
> > >
> > > Claus Schneider(Eficode) (5):
> > >   read-cache: update add_files_to_cache take param
> > >     include_ignored_submodules
> > >   read-cache: add/read-cache respect submodule ignore=all
> > >   tests: add new t2206-add-submodule-ignored.sh to test ignore=all
> > >     scenario
> > >   tests: fix existing tests when add an ignore=all submodule
> > >   Documentation: add --include_ignored_submodules + ignore=all config
> > >
> > >  .devcontainer/Dockerfile            |  70 +++++++++++++++
> > >  .devcontainer/Dockerfile.standalone |  76 ++++++++++++++++
> > >  .devcontainer/devcontainer.json     |  25 ++++++
> > >  Documentation/config/submodule.adoc |  13 +--
> > >  Documentation/git-add.adoc          |   5 ++
> > >  Documentation/gitmodules.adoc       |   5 +-
> > >  builtin/add.c                       |   4 +-
> > >  builtin/checkout.c                  |   2 +-
> > >  builtin/commit.c                    |   2 +-
> > >  read-cache-ll.h                     |   2 +-
> > >  read-cache.c                        |  54 ++++++++++-
> > >  t/lib-submodule-update.sh           |   6 +-
> > >  t/meson.build                       |   1 +
> > >  t/t2206-add-submodule-ignored.sh    | 134 ++++++++++++++++++++++++++++
> > >  t/t7508-status.sh                   |   2 +-
> > >  15 files changed, 384 insertions(+), 17 deletions(-)
> > >  create mode 100644 .devcontainer/Dockerfile
> > >  create mode 100644 .devcontainer/Dockerfile.standalone
> > >  create mode 100644 .devcontainer/devcontainer.json
> > >  create mode 100755 t/t2206-add-submodule-ignored.sh
> > >
> > >
> > > base-commit: 81f86aacc4eb74cdb9c2c8082d36d2070c666045
> > > Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-1987%2FPraqma%2Frespect-submodule-ignore-v2
> > > Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-1987/Praqma/respect-submodule-ignore-v2
> > > Pull-Request: https://github.com/gitgitgadget/git/pull/1987
> > >
> > > Range-diff vs v1:
> > >
> > >  1:  d98cca698d ! 1:  5796009122 read-cache: update add_files_to_cache to take param ignored_too(--force)
> > >      @@ Metadata
> > >       Author: Claus Schneider(Eficode) <claus.schneider@eficode.com>
> > >
> > >        ## Commit message ##
> > >      -    read-cache: update add_files_to_cache to take param ignored_too(--force)
> > >      +    read-cache: update add_files_to_cache take param include_ignored_submodules
> > >
> > >      -    The ignored_too parameter is added to the function add_files_to_cache for
> > >      -    usage of explicit updating the index for the updated submodule using the
> > >      -    explicit patchspec to the submodule.
> > >      +    The include_ignored_submodules parameter is added to the function
> > >      +    add_files_to_cache for usage of explicit updating the index for the updated
> > >      +    submodule using the explicit patchspec to the submodule.
> > >
> > >           Signed-off-by: Claus Schneider(Eficode) <claus.schneider@eficode.com>
> > >
> > >        ## builtin/add.c ##
> > >      +@@ builtin/add.c: N_("The following paths are ignored by one of your .gitignore files:\n");
> > >      + static int verbose, show_only, ignored_too, refresh_only;
> > >      + static int ignore_add_errors, intent_to_add, ignore_missing;
> > >      + static int warn_on_embedded_repo = 1;
> > >      ++static int include_ignored_submodules;
> > >      +
> > >      + #define ADDREMOVE_DEFAULT 1
> > >      + static int addremove = ADDREMOVE_DEFAULT;
> > >      +@@ builtin/add.c: static struct option builtin_add_options[] = {
> > >      +        OPT_BOOL( 0 , "ignore-errors", &ignore_add_errors, N_("just skip files which cannot be added because of errors")),
> > >      +        OPT_BOOL( 0 , "ignore-missing", &ignore_missing, N_("check if - even missing - files are ignored in dry run")),
> > >      +        OPT_BOOL(0, "sparse", &include_sparse, N_("allow updating entries outside of the sparse-checkout cone")),
> > >      ++    OPT_BOOL(0, "include-ignored-submodules", &include_ignored_submodules, N_("add submodules even if they has configuration ignore=all")),
> > >      +        OPT_STRING(0, "chmod", &chmod_arg, "(+|-)x",
> > >      +                   N_("override the executable bit of the listed files")),
> > >      +        OPT_HIDDEN_BOOL(0, "warn-embedded-repo", &warn_on_embedded_repo,
> > >       @@ builtin/add.c: int cmd_add(int argc,
> > >               else
> > >                       exit_status |= add_files_to_cache(repo, prefix,
> > >                                                         &pathspec, ps_matched,
> > >       -                                                 include_sparse, flags);
> > >      -+                                                 include_sparse, flags, ignored_too);
> > >      ++                                                 include_sparse, flags, include_ignored_submodules);
> > >
> > >               if (take_worktree_changes && !add_renormalize && !ignore_add_errors &&
> > >                   report_path_error(ps_matched, &pathspec))
> > >      @@ read-cache.c: void overlay_tree_on_index(struct index_state *istate,
> > >               int include_sparse;
> > >               int flags;
> > >               int add_errors;
> > >      -+       int ignored_too;
> > >      ++       int include_ignored_submodules;
> > >        };
> > >
> > >        static int fix_unmerged_status(struct diff_filepair *p,
> > >       @@ read-cache.c: static void update_callback(struct diff_queue_struct *q,
> > >      +                default:
> > >      +                        die(_("unexpected diff status %c"), p->status);
> > >      +                case DIFF_STATUS_MODIFIED:
> > >      +-               case DIFF_STATUS_TYPE_CHANGED:
> > >      ++               case DIFF_STATUS_TYPE_CHANGED: {
> > >      ++                       struct stat st;
> > >      ++                       if (!lstat(path, &st) && S_ISDIR(st.st_mode)) { // only consider submodule if it is a directory
> > >      ++                               const struct submodule *sub = submodule_from_path(data->repo, null_oid(the_hash_algo), path);
> > >      ++                               if (sub && sub->name && sub->ignore && !strcmp(sub->ignore, "all")) {
> > >      ++                                       int pathspec_matches = 0;
> > >      ++                                       char *norm_pathspec = NULL;
> > >      ++                                       int ps_i;
> > >      ++                                       trace_printf("ignore=all %s\n", path);
> > >      ++                                       trace_printf("pathspec %s\n",
> > >      ++                                                       (data->pathspec && data->pathspec->nr) ? "has pathspec" : "no pathspec");
> > >      ++                                       /* Safely scan all pathspec items (q->nr may exceed pathspec->nr). */
> > >      ++                                       if (data->pathspec) {
> > >      ++                                               for (ps_i = 0; ps_i < data->pathspec->nr; ps_i++) {
> > >      ++                                                       const char *m = data->pathspec->items[ps_i].match;
> > >      ++                                                       if (!m)
> > >      ++                                                               continue;
> > >      ++                                                       norm_pathspec = xstrdup(m);
> > >      ++                                                       strip_dir_trailing_slashes(norm_pathspec);
> > >      ++                                                       if (!strcmp(path, norm_pathspec)) {
> > >      ++                                                               pathspec_matches = 1;
> > >      ++                                                               FREE_AND_NULL(norm_pathspec);
> > >      ++                                                               break;
> > >      ++                                                       }
> > >      ++                                                       FREE_AND_NULL(norm_pathspec);
> > >      ++                                               }
> > >      ++                                       }
> > >      ++                                       if (pathspec_matches) {
> > >      ++                                               if (data->include_ignored_submodules && data->include_ignored_submodules > 0) {
> > >      ++                                                       trace_printf("Add ignored=all submodule due to --include_ignored_submodules: %s\n", path);
> > >      ++                                               } else {
> > >      ++                                                       printf(_("Skipping submodule due to ignore=all: %s"), path);
> > >      ++                                                       printf(_("Use --include_ignored_submodules, if you really want to add them.") );
> > >      ++                                                       continue;
> > >      ++                                               }
> > >      ++                                       } else {
> > >      ++                                               /* No explicit pathspec match -> skip silently (or with trace). */
> > >      ++                                               trace_printf("pathspec does not match %s\n", path);
> > >      ++                                               continue;
> > >      ++                                       }
> > >      ++                               }
> > >      ++                       }
> > >      +                        if (add_file_to_index(data->index, path, data->flags)) {
> > >      +                                if (!(data->flags & ADD_CACHE_IGNORE_ERRORS))
> > >      +                                        die(_("updating files failed"));
> > >      +@@ read-cache.c: static void update_callback(struct diff_queue_struct *q,
> > >
> > >        int add_files_to_cache(struct repository *repo, const char *prefix,
> > >                              const struct pathspec *pathspec, char *ps_matched,
> > >       -                      int include_sparse, int flags)
> > >      -+                      int include_sparse, int flags, int ignored_too )
> > >      ++                      int include_sparse, int flags, int include_ignored_submodules )
> > >        {
> > >               struct update_callback_data data;
> > >               struct rev_info rev;
> > >      @@ read-cache.c: int add_files_to_cache(struct repository *repo, const char *prefix
> > >               data.include_sparse = include_sparse;
> > >               data.flags = flags;
> > >       +       data.repo = repo;
> > >      -+       data.ignored_too = ignored_too;
> > >      ++       data.include_ignored_submodules = include_ignored_submodules;
> > >       +       data.pathspec = (struct pathspec *)pathspec;
> > >
> > >               repo_init_revisions(repo, &rev, prefix);
> > >  2:  d1b02617e6 ! 2:  9ec79b9a11 read-cache: let read-cache respect submodule ignore=all and --force
> > >      @@ Metadata
> > >       Author: Claus Schneider(Eficode) <claus.schneider@eficode.com>
> > >
> > >        ## Commit message ##
> > >      -    read-cache: let read-cache respect submodule ignore=all and --force
> > >      +    read-cache: add/read-cache respect submodule ignore=all
> > >
> > >      -    Given the submdule configuration is ignore=all then only update the
> > >      -    submdule if the --force option is given and the submodule is explicit
> > >      -    given in the pathspec.
> > >      +    Submodules configured with ignore=all are now skipped during add operations
> > >      +    unless overridden by --include-ignored-submodules and the submodule path is
> > >      +    explicitly specified.
> > >
> > >           A message is printed (like ignored files) guiding the user to use the
> > >      -    --force flag if the user has explicitely want to update the submodule
> > >      -    reference.
> > >      +    --include-ignored-submodules flag if the user has explicitely want to update
> > >      +    the submodule reference.
> > >
> > >           The reason for the change is support submodule branch tracking or
> > >           similar and git status state nothing and git add should not add either.
> > >      @@ Commit message
> > >           the submodule is already tracked.
> > >
> > >           The change opens up a lot of possibilities for submodules to be used
> > >      -    more freely and a like the repo tool. A submodule can be added for many
> > >      +    more freely and simular to the repo tool. A submodule can be added for many
> > >           more reason and loosely coupled dependencies to the super repo which often
> > >           gives the friction of handle the explicit commits and updates without
> > >           the need for tracking the submodule sha1 by sha1.
> > >      @@ read-cache.c
> > >        /* Mask for the name length in ce_flags in the on-disk index */
> > >
> > >       @@ read-cache.c: static void update_callback(struct diff_queue_struct *q,
> > >      -                default:
> > >      -                        die(_("unexpected diff status %c"), p->status);
> > >      -                case DIFF_STATUS_MODIFIED:
> > >      --               case DIFF_STATUS_TYPE_CHANGED:
> > >      -+               case DIFF_STATUS_TYPE_CHANGED: {
> > >      -+                       struct stat st;
> > >      -+                       if (!lstat(path, &st) && S_ISDIR(st.st_mode)) { // only consider submodule if it is a directory
> > >      -+                               const struct submodule *sub = submodule_from_path(data->repo, null_oid(the_hash_algo), path);
> > >      -+                               if (sub && sub->name && sub->ignore && !strcmp(sub->ignore, "all")) {
> > >      -+                                       int pathspec_matches = 0;
> > >      -+                                       char *norm_pathspec = NULL;
> > >      -+                                       int ps_i;
> > >      -+                                       trace_printf("ignore=all %s\n", path);
> > >      -+                                       trace_printf("pathspec %s\n",
> > >      -+                                                       (data->pathspec && data->pathspec->nr) ? "has pathspec" : "no pathspec");
> > >      -+                                       /* Safely scan all pathspec items (q->nr may exceed pathspec->nr). */
> > >      -+                                       if (data->pathspec) {
> > >      -+                                               for (ps_i = 0; ps_i < data->pathspec->nr; ps_i++) {
> > >      -+                                                       const char *m = data->pathspec->items[ps_i].match;
> > >      -+                                                       if (!m)
> > >      -+                                                               continue;
> > >      -+                                                       norm_pathspec = xstrdup(m);
> > >      -+                                                       strip_dir_trailing_slashes(norm_pathspec);
> > >      -+                                                       if (!strcmp(path, norm_pathspec)) {
> > >      -+                                                               pathspec_matches = 1;
> > >      -+                                                               FREE_AND_NULL(norm_pathspec);
> > >      -+                                                               break;
> > >      -+                                                       }
> > >      -+                                                       FREE_AND_NULL(norm_pathspec);
> > >      -+                                               }
> > >      -+                                       }
> > >      -+                                       if (pathspec_matches) {
> > >      -+                                               if (data->ignored_too && data->ignored_too > 0) {
> > >      -+                                                       trace_printf("Forcing add of submodule ignored=all due to --force: %s\n", path);
> > >      -+                                               } else {
> > >      -+                                                       printf(_("Skipping submodule due to ignore=all: %s"), path);
> > >      -+                                                       printf(_("Use -f if you really want to add them.") );
> > >      -+                                                       continue;
> > >      -+                                               }
> > >      -+                                       } else {
> > >      -+                                               /* No explicit pathspec match -> skip silently (or with trace). */
> > >      -+                                               trace_printf("pathspec does not match %s\n", path);
> > >      -+                                               continue;
> > >      -+                                       }
> > >      -+                               }
> > >      -+                       }
> > >      -                        if (add_file_to_index(data->index, path, data->flags)) {
> > >      -                                if (!(data->flags & ADD_CACHE_IGNORE_ERRORS))
> > >      -                                        die(_("updating files failed"));
> > >      +                                        }
> > >      +                                        if (pathspec_matches) {
> > >      +                                                if (data->include_ignored_submodules && data->include_ignored_submodules > 0) {
> > >      +-                                                       trace_printf("Add ignored=all submodule due to --include_ignored_submodules: %s\n", path);
> > >      ++                                                       trace_printf("Add submodule due to --include_ignored_submodules: %s\n", path);
> > >      +                                                } else {
> > >      +                                                        printf(_("Skipping submodule due to ignore=all: %s"), path);
> > >      +                                                        printf(_("Use --include_ignored_submodules, if you really want to add them.") );
> > >      +@@ read-cache.c: static void update_callback(struct diff_queue_struct *q,
> > >      +                                                }
> > >      +                                        } else {
> > >      +                                                /* No explicit pathspec match -> skip silently (or with trace). */
> > >      +-                                               trace_printf("pathspec does not match %s\n", path);
> > >      ++                                               trace_printf("Pathspec to submodule does not match explicitly: %s\n", path);
> > >      +                                                continue;
> > >      +                                        }
> > >      +                                }
> > >      +@@ read-cache.c: static void update_callback(struct diff_queue_struct *q,
> > >                                       data->add_errors++;
> > >                               }
> > >                               break;
> > >  3:  8f3d5f7ec1 ! 3:  399a153b95 tests: add new t2206-add-submodule-ignored.sh to test ignore=all scenario
> > >      @@ Commit message
> > >           config with ignore=all also behaves as intended with configuration in
> > >           .gitmodules and configuration given on the command line.
> > >
> > >      -    Testfile is added to meson.build for execution.
> > >      +    The usage of --include_ignored_submodules is showcased and tested in the
> > >      +    test suite.
> > >      +
> > >      +    The test file is added to meson.build for execution.
> > >
> > >           Signed-off-by: Claus Schneider(Eficode) <claus.schneider@eficode.com>
> > >
> > >      @@ t/t2206-add-submodule-ignored.sh (new)
> > >       +# This test covers the behavior of "git add", "git status" and "git log" when
> > >       +# dealing with submodules that have the ignore=all setting in
> > >       +# .gitmodules. It ensures that changes in such submodules are
> > >      -+# ignored by default, but can be staged with "git add --force".
> > >      ++# ignored by default, but can be staged with "git add --include-ignored-submodules".
> > >       +
> > >       +# shellcheck disable=SC1091
> > >       +. ./test-lib.sh
> > >      @@ t/t2206-add-submodule-ignored.sh (new)
> > >       +'
> > >       +
> > >       +#6
> > >      -+# check that 'git add --force .' does not stage the change in the submodule
> > >      ++# check that 'git add --include-ignored-submodules .' does not stage the change in the submodule
> > >       +# and that 'git status' does not show it as modified
> > >      -+test_expect_success 'main: check --force add . and status'  '
> > >      ++test_expect_success 'main: check --include-ignored-submodules add . and status'  '
> > >       +       cd "${base_path}" &&
> > >       +       cd main &&
> > >      -+       GIT_TRACE=1 git add --force . &&
> > >      ++       GIT_TRACE=1 git add --include-ignored-submodules . &&
> > >       +       ! git status --porcelain | grep "^M  sub$" &&
> > >       +       echo
> > >       +'
> > >      @@ t/t2206-add-submodule-ignored.sh (new)
> > >       +'
> > >       +
> > >       +#8
> > >      -+# check that 'git add --force sub' does stage the change in the submodule
> > >      -+# check that 'git add --force ./sub/' does stage the change in the submodule
> > >      ++# check that 'git add --include-ignored-submodules sub' does stage the change in the submodule
> > >      ++# check that 'git add --include-ignored-submodules ./sub/' does stage the change in the submodule
> > >       +# and that 'git status --porcelain' does show it as modified
> > >       +# commit it..
> > >       +# check that 'git log --ignore-submodules=none' shows the submodule change
> > >      @@ t/t2206-add-submodule-ignored.sh (new)
> > >       +test_expect_success 'main: check force add sub and ./sub/ and status'  '
> > >       +       cd "${base_path}" &&
> > >       +       cd main &&
> > >      -+       echo "Adding with --force should work: git add --force sub" &&
> > >      -+       GIT_TRACE=1 git add --force sub &&
> > >      ++       echo "Adding with --include-ignored-submodules should work: git add --include-ignored-submodules sub" &&
> > >      ++       GIT_TRACE=1 git add --include-ignored-submodules sub &&
> > >       +       git status --porcelain | grep "^M  sub$" &&
> > >       +       git restore --staged sub &&
> > >       +       ! git status --porcelain | grep "^M  sub$" &&
> > >      -+       echo "Adding with --force should work: git add --force ./sub/" &&
> > >      -+       GIT_TRACE=1 git add --force ./sub/ &&
> > >      ++       echo "Adding with --include-ignored-submodules should work: git add --include-ignored-submodules ./sub/" &&
> > >      ++       GIT_TRACE=1 git add --include-ignored-submodules ./sub/ &&
> > >       +       git status --porcelain | grep "^M  sub$" &&
> > >       +       git commit -m "update submodule pointer" &&
> > >       +       ! git status --porcelain | grep "^ M sub$" &&
> > >  4:  58563a7b90 ! 4:  93c95954f1 tests: fix existing tests when add an ignore=all submodule
> > >      @@ Metadata
> > >        ## Commit message ##
> > >           tests: fix existing tests when add an ignore=all submodule
> > >
> > >      -    There are tests that rely on "git add <submodule>" also adds it. A --force
> > >      -    is needed with this enhancement hence they are added accordingly in these
> > >      -    tests.
> > >      +    There are tests that rely on "git add <submodule>" to add updates in the
> > >      +    parent repository. A new option --include-ignored-submodules is introduced
> > >      +    as it is now needed with this enhancement.
> > >
> > >           Updated tests:
> > >           - t1013-read-tree-submodule.sh ( fixed in: t/lib-submodule-update.sh )
> > >      +    - t2013-checkout-submodule.sh ( fixed in: t/lib-submodule-update.sh )
> > >           - t7406-submodule-update.sh
> > >           - t7508-status.sh
> > >
> > >      @@ t/lib-submodule-update.sh: create_lib_submodule_repo () {
> > >                               git push origin modifications
> > >                       ) &&
> > >       -               git add sub1 &&
> > >      -+               git add --force sub1 &&
> > >      ++               git add --include-ignored-submodules sub1 &&
> > >                       git commit -m "Modify sub1" &&
> > >
> > >                       git checkout -b add_nested_sub modify_sub1 &&
> > >      @@ t/lib-submodule-update.sh: create_lib_submodule_repo () {
> > >                       git -C sub1 submodule add --branch no_submodule ../submodule_update_sub2 sub2 &&
> > >                       git -C sub1 commit -a -m "add a nested submodule" &&
> > >       -               git add sub1 &&
> > >      -+               git add --force sub1 &&
> > >      ++               git add --include-ignored-submodules sub1 &&
> > >                       git commit -a -m "update submodule, that updates a nested submodule" &&
> > >                       git checkout -b modify_sub1_recursively &&
> > >                       git -C sub1 checkout -b modify_sub1_recursively &&
> > >      @@ t/lib-submodule-update.sh: create_lib_submodule_repo () {
> > >                       git -C sub1 add sub2 &&
> > >                       git -C sub1 commit -m "update nested sub" &&
> > >       -               git add sub1 &&
> > >      -+               git add --force sub1 &&
> > >      ++               git add --include-ignored-submodules sub1 &&
> > >                       git commit -m "update sub1, that updates nested sub" &&
> > >                       git -C sub1 push origin modify_sub1_recursively &&
> > >                       git -C sub1/sub2 push origin modify_sub1_recursively &&
> > >      @@ t/t7508-status.sh: test_expect_success 'git commit will commit a staged but igno
> > >        test_expect_success 'git commit --dry-run will show a staged but ignored submodule' '
> > >               git reset HEAD^ &&
> > >       -       git add sm &&
> > >      -+       git add --force sm &&
> > >      ++       git add --include-ignored-submodules sm &&
> > >               cat >expect << EOF &&
> > >        On branch main
> > >        Your branch and '\''upstream'\'' have diverged,
> > >  5:  416695f439 < -:  ---------- Documentation: update add --force and submodule ignore=all config
> > >  -:  ---------- > 5:  ee84190cd8 Documentation: add --include_ignored_submodules + ignore=all config
Junio C Hamano· Feb 5, 2026, 22:05 UTC · re: Claus Schneider · lore

Re: [PATCH v2 0/5] git-add : Respect submodule ignore=all and only add changes with --force

Claus Schneider <claus.schneider@eficode.com> writes:
Show 7 quoted lines
> Hi
>
> I have implemented the --ignore option. I believe it is done. Please
> review it again for integration to 'next'.
>
> Best regards
> Claus Schneider

Sorry, but I am confused to see this follow-up to [v2 0/5], after I saw at least two messages from you that said something like

    Thanks for feedback. Noted and will be fixed as this:

in review thread for the [v3]. I admit that "What's cooking" report often has stale entries, but for this topic, I think its recent editions reflect the latest status of this thread correctly.

* cs/add-skip-submodule-ignore-all (2026-01-13) 5 commits
 - Documentation: update add --force option + ignore=all config
 - tests: fix existing tests when add an ignore=all submodule
 - tests: t2206-add-submodule-ignored: ignore=all and add --force tests
 - read-cache: submodule add need --force given ignore=all configuration
 - read-cache: update add_files_to_cache take param ignored_too
 "git add <submodule>" has been taught to honor
 submodule.<name>.ignore that is set to "all" (and requires "git add
 -f" to override it).
 Expecting a reroll.
 cf. <CA+GP4bqY02wcESuz1vPMcknigx_fUXFfi_xQ1EG_muGw6EszRg@mail.gmail.com>
 cf. <CA+GP4bpwMui5RT9ixo8iWyZ6XZDw3GnYhvgiqVmRq8dW7yo5RQ@mail.gmail.com>
 source: <37fe7956e089394bb1d75f4c8af4a3347b204803.1768376879.git.gitgitgadget@gmail.com>
Claus Schneider via GitGitGadget· Feb 6, 2026, 13:22 UTC · re: Claus Schneider via GitGitGadget · lore

[PATCH v4 0/5] git-add: Skip submodules with ignore=all unless --force and explicit path used

The ignore=all configuration for submodules is currently honored by status and diff, but not by add. This inconsistency causes friction when working with submodules:

 * Developers unintentionally stage submodule updates, leading to conflicts
   and unnecessary changes.
 * Tracking branches in submodule configs causes friction as updates to the
   submodule SHA1 are added without intent.
This patch aligns git add with the behavior of status and diff:
 * Submodules marked ignore=all are skipped by default.
 * Attempting to add such a submodule explicitly now requires --force.

A submodule can frictionless track a branch in the configuration or manually switched to and use update --update --remote without unintentionally add the changes to the super-project.

Tests that previously added submodules without --force have been updated accordingly. A new test is added to test the behavior of git add with and without --force.

Claus Schneider(Eficode) (5):
  read-cache: update add_files_to_cache take param ignored_too
  read-cache: submodule add need --force given ignore=all configuration
  tests: t2206-add-submodule-ignored: ignore=all and add --force tests
  tests: fix existing tests when add an ignore=all submodule
  Documentation: update add --force option + ignore=all config
 Documentation/config/submodule.adoc |  13 +--
 Documentation/git-add.adoc          |   5 +-
 Documentation/gitmodules.adoc       |   5 +-
 builtin/add.c                       |   2 +-
 builtin/checkout.c                  |   2 +-
 builtin/commit.c                    |   2 +-
 read-cache-ll.h                     |   2 +-
 read-cache.c                        |  80 ++++++++++++++++-
 t/lib-submodule-update.sh           |   6 +-
 t/meson.build                       |   1 +
 t/t2206-add-submodule-ignored.sh    | 134 ++++++++++++++++++++++++++++
 t/t7508-status.sh                   |   2 +-
 12 files changed, 235 insertions(+), 19 deletions(-)
 create mode 100755 t/t2206-add-submodule-ignored.sh
base-commit: 9a2fb147f2c61d0cab52c883e7e26f5b7948e3ed
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-1987%2FPraqma%2Frespect-submodule-ignore-v4
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-1987/Praqma/respect-submodule-ignore-v4
Pull-Request: https://github.com/gitgitgadget/git/pull/1987
Range-diff vs v3:
 1:  d2b66286c2 = 1:  69e0065b1b read-cache: update add_files_to_cache take param ignored_too
 2:  de72bf0a91 ! 2:  504edcb0f5 read-cache: submodule add need --force given ignore=all configuration
     @@ Commit message
          unless overridden by --force and the submodule path is explicitly specified.
      
          A message is printed (like ignored files) guiding the user to use the
     -    --force flag if the user has explicitely want to update the submodule
     -    reference.
     +    --force flag if the user explicitly wants to update the submodule reference.
      
     -    The reason for the change is support submodule branch tracking or
     -    similar and git status states nothing and git add should not add either
     -    as a default behaviour. The workflow is more logic and similar to regular
     -    ignored files even the submodule is already tracked.
     +    The reason for the change is to support branch tracking in submodules
     +    with configuration `submdule.<name>.branch` or similar workflows where the
     +    user is not interested in tracking each update of the sha1 in the submdule.
     +    You can additionally set `submodule.<name>.ignore=all` and the `git status`
     +    will state nothing and, with this patch, the `git add` does not either - as
     +    the default behaviour. This patch changes the workflow to a more logical
     +    behaviour and similar to workflow for ignored files.
      
     -    The change opens up a lot of possibilities for submodules to be used
     -    more freely and simular to the repo tool. A submodule can be added for many
     -    more reason and loosely coupled dependencies to the super repo which often
     -    gives the friction of handle the explicit commits and updates without
     -    the need for tracking the submodule sha1 by sha1.
     +    The patch gives more scenarios for submodules to be used effectively with
     +    less friction similar to the "repo" tool. A submodule can be added for many
     +    different reasons than a hard dependency. It can be added as loosely
     +    coupled dependencies whereas the user wants the latest based on the
     +    configuration `submoule.<name>.branch`, but are not interested to track
     +    each commit in the `super-repo`. Currently it gives friction of handling
     +    conflicts between branches even the sha1's are fast-forward and the user
     +    just wants the latest in any way. The user can still add a sha1 explicitly
     +    to track updates.
      
          Signed-off-by: Claus Schneider(Eficode) <claus.schneider@eficode.com>
      
 3:  d7b97e12d3 = 3:  d5ea8eb6e0 tests: t2206-add-submodule-ignored: ignore=all and add --force tests
 4:  6e44ab6804 = 4:  df5c85d9f2 tests: fix existing tests when add an ignore=all submodule
 5:  37fe7956e0 ! 5:  8bfaa14d44 Documentation: update add --force option + ignore=all config
     @@ Documentation/config/submodule.adoc: submodule.<name>.fetchRecurseSubmodules::
      -	commit when it has been staged), "dirty" will ignore all changes
      -	to the submodule's work tree and
      +	a submodule as modified.
     -+	Set to "all" will never consider the submodule modified. It can
     ++	When set to "all" will never consider the submodule modified. It can
      +	nevertheless be staged using the option --force and it will then show up
      +	in the output of status.
     -+	Set to "dirty" will ignore all changes to the submodule's work tree and
     ++	When set to "dirty" will ignore all changes to the submodule's work tree and
       	takes only differences between the HEAD of the submodule and the commit
       	recorded in the superproject into account. "untracked" will additionally
       	let submodules with modified tracked files in their work tree show up.
      -	Using "none" (the default when this option is not set) also shows
      -	submodules that have untracked files in their work tree as changed.
     -+	Set to "none"(default) It is also shows submodules that have untracked
     -+	files in their work tree as changed.
     ++	When set to "none"(default) It also show submodules as changed if they have
     ++	untracked files in their work tree.
       	This setting overrides any setting made in .gitmodules for this submodule,
       	both settings can be overridden on the command line by using the
       	"--ignore-submodules" option. The 'git submodule' commands are not
-- 
gitgitgadget
Claus Schneider(Eficode) via GitGitGadget· Feb 6, 2026, 13:22 UTC · re: Claus Schneider via GitGitGadget · lore

[PATCH v4 1/5] read-cache: update add_files_to_cache take param ignored_too

From: "Claus Schneider(Eficode)" <claus.schneider@eficode.com>

The ignored_too parameter is added to the function add_files_to_cache for usage of explicit updating the index for the updated submodule using the explicit patchspec to the submodule.

Signed-off-by: Claus Schneider(Eficode) <claus.schneider@eficode.com>
---
 builtin/add.c      |  2 +-
 builtin/checkout.c |  2 +-
 builtin/commit.c   |  2 +-
 read-cache-ll.h    |  2 +-
 read-cache.c       | 10 ++++++++--
 5 files changed, 12 insertions(+), 6 deletions(-)
Show changes to 5 files +12 −6

builtin/add.c, builtin/checkout.c, builtin/commit.c, read-cache-ll.h, read-cache.c

diff --git a/builtin/add.c b/builtin/add.c
index 32709794b3..eef4959ee3 100644
--- a/builtin/add.c
+++ b/builtin/add.c
@@ -584,7 +584,7 @@ int cmd_add(int argc,
 	else
 		exit_status |= add_files_to_cache(repo, prefix,
 						  &pathspec, ps_matched,
-						  include_sparse, flags);
+						  include_sparse, flags, ignored_too);
 
 	if (take_worktree_changes && !add_renormalize && !ignore_add_errors &&
 	    report_path_error(ps_matched, &pathspec))
diff --git a/builtin/checkout.c b/builtin/checkout.c
index f9453473fe..88d6a68022 100644
--- a/builtin/checkout.c
+++ b/builtin/checkout.c
@@ -899,7 +899,7 @@ static int merge_working_tree(const struct checkout_opts *opts,
 			 */
 
 			add_files_to_cache(the_repository, NULL, NULL, NULL, 0,
-					   0);
+					0, 0);
 			init_ui_merge_options(&o, the_repository);
 			o.verbosity = 0;
 			work = write_in_core_index_as_tree(the_repository);
diff --git a/builtin/commit.c b/builtin/commit.c
index 0243f17d53..1a00642090 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -455,7 +455,7 @@ static const char *prepare_index(const char **argv, const char *prefix,
 		repo_hold_locked_index(the_repository, &index_lock,
 				       LOCK_DIE_ON_ERROR);
 		add_files_to_cache(the_repository, also ? prefix : NULL,
-				   &pathspec, ps_matched, 0, 0);
+				   &pathspec, ps_matched, 0, 0, 0 );
 		if (!all && report_path_error(ps_matched, &pathspec))
 			exit(128);
 
diff --git a/read-cache-ll.h b/read-cache-ll.h
index 71b49d9af4..2c8b4b21b1 100644
--- a/read-cache-ll.h
+++ b/read-cache-ll.h
@@ -481,7 +481,7 @@ int cmp_cache_name_compare(const void *a_, const void *b_);
 
 int add_files_to_cache(struct repository *repo, const char *prefix,
 		       const struct pathspec *pathspec, char *ps_matched,
-		       int include_sparse, int flags);
+		       int include_sparse, int flags, int ignored_too );
 
 void overlay_tree_on_index(struct index_state *istate,
 			   const char *tree_name, const char *prefix);
diff --git a/read-cache.c b/read-cache.c
index 032480d0c7..0f4981d79f 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -3881,9 +3881,12 @@ void overlay_tree_on_index(struct index_state *istate,
 
 struct update_callback_data {
 	struct index_state *index;
+	struct repository *repo;
+	struct pathspec *pathspec;
 	int include_sparse;
 	int flags;
 	int add_errors;
+	int ignored_too;
 };
 
 static int fix_unmerged_status(struct diff_filepair *p,
@@ -3925,7 +3928,7 @@ static void update_callback(struct diff_queue_struct *q,
 		default:
 			die(_("unexpected diff status %c"), p->status);
 		case DIFF_STATUS_MODIFIED:
-		case DIFF_STATUS_TYPE_CHANGED:
+		case DIFF_STATUS_TYPE_CHANGED: {
 			if (add_file_to_index(data->index, path, data->flags)) {
 				if (!(data->flags & ADD_CACHE_IGNORE_ERRORS))
 					die(_("updating files failed"));
@@ -3946,7 +3949,7 @@ static void update_callback(struct diff_queue_struct *q,
 
 int add_files_to_cache(struct repository *repo, const char *prefix,
 		       const struct pathspec *pathspec, char *ps_matched,
-		       int include_sparse, int flags)
+		       int include_sparse, int flags, int ignored_too )
 {
 	struct odb_transaction *transaction;
 	struct update_callback_data data;
@@ -3956,6 +3959,9 @@ int add_files_to_cache(struct repository *repo, const char *prefix,
 	data.index = repo->index;
 	data.include_sparse = include_sparse;
 	data.flags = flags;
+	data.repo = repo;
+	data.ignored_too = ignored_too;
+	data.pathspec = (struct pathspec *)pathspec;
 
 	repo_init_revisions(repo, &rev, prefix);
 	setup_revisions(0, NULL, &rev, NULL);
-- 
gitgitgadget
Claus Schneider(Eficode) via GitGitGadget· Feb 6, 2026, 13:22 UTC · re: Claus Schneider via GitGitGadget · lore

[PATCH v4 2/5] read-cache: submodule add need --force given ignore=all configuration

From: "Claus Schneider(Eficode)" <claus.schneider@eficode.com>

Submodules configured with ignore=all are now skipped during add operations unless overridden by --force and the submodule path is explicitly specified.

A message is printed (like ignored files) guiding the user to use the --force flag if the user explicitly wants to update the submodule reference.

The reason for the change is to support branch tracking in submodules with configuration `submdule.<name>.branch` or similar workflows where the user is not interested in tracking each update of the sha1 in the submdule. You can additionally set `submodule.<name>.ignore=all` and the `git status` will state nothing and, with this patch, the `git add` does not either - as the default behaviour. This patch changes the workflow to a more logical behaviour and similar to workflow for ignored files.

The patch gives more scenarios for submodules to be used effectively with less friction similar to the "repo" tool. A submodule can be added for many different reasons than a hard dependency. It can be added as loosely coupled dependencies whereas the user wants the latest based on the configuration `submoule.<name>.branch`, but are not interested to track each commit in the `super-repo`. Currently it gives friction of handling conflicts between branches even the sha1's are fast-forward and the user just wants the latest in any way. The user can still add a sha1 explicitly to track updates.

Signed-off-by: Claus Schneider(Eficode) <claus.schneider@eficode.com>
---
 read-cache.c | 74 +++++++++++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 71 insertions(+), 3 deletions(-)
Show changes to read-cache.c +71 −3
diff --git a/read-cache.c b/read-cache.c
index 0f4981d79f..cc79b25f43 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -47,6 +47,9 @@
 #include "csum-file.h"
 #include "promisor-remote.h"
 #include "hook.h"
+#include "submodule.h"
+#include "submodule-config.h"
+#include "advice.h"
 
 /* Mask for the name length in ce_flags in the on-disk index */
 
@@ -3910,8 +3913,68 @@ static int fix_unmerged_status(struct diff_filepair *p,
 		return DIFF_STATUS_MODIFIED;
 }
 
+static int skip_submodule(const char *path,
+						struct repository *repo,
+						struct pathspec *pathspec,
+						int ignored_too)
+{
+    struct stat st;
+    const struct submodule *sub;
+    int pathspec_matches = 0;
+    int ps_i;
+    char *norm_pathspec = NULL;
+
+    /* Only consider if path is a directory */
+    if (lstat(path, &st) || !S_ISDIR(st.st_mode))
+		return 0;
+
+    /* Check if it's a submodule with ignore=all */
+    sub = submodule_from_path(repo, null_oid(the_hash_algo), path);
+    if (!sub || !sub->name || !sub->ignore || strcmp(sub->ignore, "all"))
+		return 0;
+
+    trace_printf("ignore=all: %s\n", path);
+    trace_printf("pathspec %s\n", (pathspec && pathspec->nr)
+									? "has pathspec"
+									: "no pathspec");
+
+    /* Check if submodule path is explicitly mentioned in pathspec */
+    if (pathspec) {
+		for (ps_i = 0; ps_i < pathspec->nr; ps_i++) {
+			const char *m = pathspec->items[ps_i].match;
+			if (!m)
+				continue;
+			norm_pathspec = xstrdup(m);
+			strip_dir_trailing_slashes(norm_pathspec);
+			if (!strcmp(path, norm_pathspec)) {
+				pathspec_matches = 1;
+				FREE_AND_NULL(norm_pathspec);
+				break;
+			}
+			FREE_AND_NULL(norm_pathspec);
+		}
+    }
+
+    /* If explicitly matched and forced, allow adding */
+    if (pathspec_matches) {
+		if (ignored_too && ignored_too > 0) {
+			trace_printf("Add submodule due to --force: %s\n", path);
+			return 0;
+		} else {
+			advise_if_enabled(ADVICE_ADD_IGNORED_FILE,
+				_("Skipping submodule due to ignore=all: %s\n"
+					"Use --force if you really want to add the submodule."), path);
+			return 1;
+		}
+    }
+
+    /* No explicit pathspec match -> skip silently */
+    trace_printf("Pathspec to submodule does not match explicitly: %s\n", path);
+    return 1;
+}
+
 static void update_callback(struct diff_queue_struct *q,
-			    struct diff_options *opt UNUSED, void *cbdata)
+							struct diff_options *opt UNUSED, void *cbdata)
 {
 	int i;
 	struct update_callback_data *data = cbdata;
@@ -3921,14 +3984,19 @@ static void update_callback(struct diff_queue_struct *q,
 		const char *path = p->one->path;
 
 		if (!data->include_sparse &&
-		    !path_in_sparse_checkout(path, data->index))
+			!path_in_sparse_checkout(path, data->index))
 			continue;
 
 		switch (fix_unmerged_status(p, data)) {
 		default:
 			die(_("unexpected diff status %c"), p->status);
 		case DIFF_STATUS_MODIFIED:
-		case DIFF_STATUS_TYPE_CHANGED: {
+		case DIFF_STATUS_TYPE_CHANGED:
+			if (skip_submodule(path, data->repo,
+								data->pathspec,
+								data->ignored_too))
+				continue;
+
 			if (add_file_to_index(data->index, path, data->flags)) {
 				if (!(data->flags & ADD_CACHE_IGNORE_ERRORS))
 					die(_("updating files failed"));
-- 
gitgitgadget
Claus Schneider(Eficode) via GitGitGadget· Feb 6, 2026, 13:22 UTC · re: Claus Schneider via GitGitGadget · lore

[PATCH v4 3/5] tests: t2206-add-submodule-ignored: ignore=all and add --force tests

From: "Claus Schneider(Eficode)" <claus.schneider@eficode.com>

The tests verify that the submodule behavior is intact and updating the config with ignore=all also behaves as intended with configuration in .gitmodules and configuration given on the command line.

The usage of --force is showcased and tested in the test suite.
The test file is added to meson.build for execution.
Signed-off-by: Claus Schneider(Eficode) <claus.schneider@eficode.com>
---
 t/meson.build                    |   1 +
 t/t2206-add-submodule-ignored.sh | 134 +++++++++++++++++++++++++++++++
 2 files changed, 135 insertions(+)
 create mode 100755 t/t2206-add-submodule-ignored.sh
Show changes to 2 files +135 −0

t/meson.build, t/t2206-add-submodule-ignored.sh

diff --git a/t/meson.build b/t/meson.build
index a5531df415..a7d3e3e0a2 100644
--- a/t/meson.build
+++ b/t/meson.build
@@ -290,6 +290,7 @@ integration_tests = [
   't2203-add-intent.sh',
   't2204-add-ignored.sh',
   't2205-add-worktree-config.sh',
+  't2206-add-submodule-ignored.sh',
   't2300-cd-to-toplevel.sh',
   't2400-worktree-add.sh',
   't2401-worktree-prune.sh',
diff --git a/t/t2206-add-submodule-ignored.sh b/t/t2206-add-submodule-ignored.sh
new file mode 100755
index 0000000000..e581e87ab2
--- /dev/null
+++ b/t/t2206-add-submodule-ignored.sh
@@ -0,0 +1,134 @@
+#!/bin/sh
+# shellcheck disable=SC2016
+
+# shellcheck disable=SC2034
+test_description='git add respects submodule ignore=all and explicit pathspec'
+
+# This test covers the behavior of "git add", "git status" and "git log" when
+# dealing with submodules that have the ignore=all setting in
+# .gitmodules. It ensures that changes in such submodules are
+# ignored by default, but can be staged with "git add --force".
+
+# shellcheck disable=SC1091
+. ./test-lib.sh
+
+GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
+export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
+
+base_path=$(pwd -P)
+
+#1
+test_expect_success 'setup: create origin repos'  '
+	cd "${base_path}" &&
+	git config --global protocol.file.allow always &&
+	git init sub &&
+		pwd &&
+		cd sub &&
+		test_commit sub_file1 &&
+		git tag v1.0 &&
+		test_commit sub_file2 &&
+		git tag v2.0 &&
+		test_commit sub_file3 &&
+		git tag v3.0 &&
+	cd "${base_path}" &&
+	git init main &&
+		cd main &&
+		test_commit first &&
+	cd "${base_path}"
+'
+#2
+# add submodule with default config (ignore=none) and
+# check log that is contains a path entry for the submodule 'sub'
+# change the commit in the submodule and check that 'git status' shows it as modified
+test_expect_success 'main: add submodule with default config'  '
+	cd "${base_path}" &&
+	cd main &&
+	git submodule add ../sub &&
+	git commit -m "add submodule" &&
+	git log --oneline --name-only | grep "^sub$" &&
+	git -C sub reset --hard v2.0 &&
+	git status --porcelain | grep "^ M sub$" &&
+	echo
+'
+#3
+# change the submodule config to ignore=all and check that status and log do not show changes
+test_expect_success 'main: submodule config ignore=all'  '
+	cd "${base_path}" &&
+	cd main &&
+	git config -f .gitmodules submodule.sub.ignore all &&
+	GIT_TRACE=1 git add . &&
+	git commit -m "update submodule config sub.ignore all" &&
+	! git status --porcelain | grep "^.*$" &&
+	! git log --oneline --name-only | grep "^sub$" &&
+	echo
+'
+#4
+# change the commit in the submodule and check that 'git status' does not show it as modified
+# but 'git status --ignore-submodules=none' does show it as modified
+test_expect_success 'sub: change to different sha1 and check status in main'  '
+	cd "${base_path}" &&
+	cd main &&
+	git -C sub reset --hard v1.0 &&
+	! git status --porcelain | grep "^ M sub$" &&
+	git status --ignore-submodules=none --porcelain | grep "^ M sub$" &&
+	echo
+'
+
+#5
+# check that normal 'git add' does not stage the change in the submodule
+test_expect_success 'main: check normal add and status'  '
+	cd "${base_path}" &&
+	cd main &&
+	GIT_TRACE=1 git add . &&
+	! git status --porcelain | grep "^ M sub$" &&
+	echo
+'
+
+#6
+# check that 'git add --force .' does not stage the change in the submodule
+# and that 'git status' does not show it as modified
+test_expect_success 'main: check --force add . and status'  '
+	cd "${base_path}" &&
+	cd main &&
+	GIT_TRACE=1 git add --force . &&
+	! git status --porcelain | grep "^M  sub$" &&
+	echo
+'
+
+#7
+# check that 'git add .' does not stage the change in the submodule
+# and that 'git status' does not show it as modified
+test_expect_success 'main: check _add sub_ and status'  '
+	cd "${base_path}" &&
+	cd main &&
+	GIT_TRACE=1 git add sub 2>&1 | grep "Skipping submodule due to ignore=all: sub" &&
+	! git status --porcelain | grep "^M  sub$" &&
+	echo
+'
+
+#8
+# check that 'git add --force sub' does stage the change in the submodule
+# check that 'git add --force ./sub/' does stage the change in the submodule
+# and that 'git status --porcelain' does show it as modified
+# commit it..
+# check that 'git log --ignore-submodules=none' shows the submodule change
+# in the log
+test_expect_success 'main: check force add sub and ./sub/ and status'  '
+	cd "${base_path}" &&
+	cd main &&
+	echo "Adding with --force should work: git add --force sub" &&
+	GIT_TRACE=1 git add --force sub &&
+	git status --porcelain | grep "^M  sub$" &&
+	git restore --staged sub &&
+	! git status --porcelain | grep "^M  sub$" &&
+	echo "Adding with --force should work: git add --force ./sub/" &&
+	GIT_TRACE=1 git add --force ./sub/ &&
+	git status --porcelain | grep "^M  sub$" &&
+	git commit -m "update submodule pointer" &&
+	! git status --porcelain | grep "^ M sub$" &&
+	git log --ignore-submodules=none --name-only --oneline | grep "^sub$" &&
+	echo
+'
+
+test_done
+exit 0
-- 
gitgitgadget
Claus Schneider(Eficode) via GitGitGadget· Feb 6, 2026, 13:22 UTC · re: Claus Schneider via GitGitGadget · lore

[PATCH v4 4/5] tests: fix existing tests when add an ignore=all submodule

From: "Claus Schneider(Eficode)" <claus.schneider@eficode.com>

There are tests that rely on "git add <submodule>" to update the in the reference in the parent repository which have been updated to use the --force option.

Updated tests:
- t1013-read-tree-submodule.sh ( fixed in: t/lib-submodule-update.sh )
- t2013-checkout-submodule.sh ( fixed in: t/lib-submodule-update.sh )
- t7406-submodule-update.sh
- t7508-status.sh
Signed-off-by: Claus Schneider(Eficode) <claus.schneider@eficode.com>
---
 t/lib-submodule-update.sh | 6 +++---
 t/t7508-status.sh         | 2 +-
 2 files changed, 4 insertions(+), 4 deletions(-)
Show changes to 2 files +4 −4

t/lib-submodule-update.sh, t/t7508-status.sh

diff --git a/t/lib-submodule-update.sh b/t/lib-submodule-update.sh
index 36f767cb74..f591de6120 100644
--- a/t/lib-submodule-update.sh
+++ b/t/lib-submodule-update.sh
@@ -95,14 +95,14 @@ create_lib_submodule_repo () {
 			git commit -m "modified file2 and added file3" &&
 			git push origin modifications
 		) &&
-		git add sub1 &&
+		git add --force sub1 &&
 		git commit -m "Modify sub1" &&
 
 		git checkout -b add_nested_sub modify_sub1 &&
 		git -C sub1 checkout -b "add_nested_sub" &&
 		git -C sub1 submodule add --branch no_submodule ../submodule_update_sub2 sub2 &&
 		git -C sub1 commit -a -m "add a nested submodule" &&
-		git add sub1 &&
+		git add --force sub1 &&
 		git commit -a -m "update submodule, that updates a nested submodule" &&
 		git checkout -b modify_sub1_recursively &&
 		git -C sub1 checkout -b modify_sub1_recursively &&
@@ -112,7 +112,7 @@ create_lib_submodule_repo () {
 		git -C sub1/sub2 commit -m "make a change in nested sub" &&
 		git -C sub1 add sub2 &&
 		git -C sub1 commit -m "update nested sub" &&
-		git add sub1 &&
+		git add --force sub1 &&
 		git commit -m "update sub1, that updates nested sub" &&
 		git -C sub1 push origin modify_sub1_recursively &&
 		git -C sub1/sub2 push origin modify_sub1_recursively &&
diff --git a/t/t7508-status.sh b/t/t7508-status.sh
index abad229e9d..a5e21bf8bf 100755
--- a/t/t7508-status.sh
+++ b/t/t7508-status.sh
@@ -1576,7 +1576,7 @@ test_expect_success 'git commit will commit a staged but ignored submodule' '
 
 test_expect_success 'git commit --dry-run will show a staged but ignored submodule' '
 	git reset HEAD^ &&
-	git add sm &&
+	git add --force sm &&
 	cat >expect << EOF &&
 On branch main
 Your branch and '\''upstream'\'' have diverged,
-- 
gitgitgadget
Claus Schneider(Eficode) via GitGitGadget· Feb 6, 2026, 13:23 UTC · re: Claus Schneider via GitGitGadget · lore

[PATCH v4 5/5] Documentation: update add --force option + ignore=all config

From: "Claus Schneider(Eficode)" <claus.schneider@eficode.com>
- git-add.adoc: Update the --force documentation for submodule behaviour
  to be added even the given configuration ignore=all.
- gitmodules.adoc and config/submodule.adoc: The submodule config
  ignore=all now need --force in order to update the index.
Signed-off-by: Claus Schneider(Eficode) <claus.schneider@eficode.com>
---
 Documentation/config/submodule.adoc | 13 +++++++------
 Documentation/git-add.adoc          |  5 ++++-
 Documentation/gitmodules.adoc       |  5 ++++-
 3 files changed, 15 insertions(+), 8 deletions(-)
Show changes to 3 files +15 −8

Documentation/config/submodule.adoc, Documentation/git-add.adoc, Documentation/gitmodules.adoc

diff --git a/Documentation/config/submodule.adoc b/Documentation/config/submodule.adoc
index 0672d99117..b3db1dc2c8 100644
--- a/Documentation/config/submodule.adoc
+++ b/Documentation/config/submodule.adoc
@@ -32,15 +32,16 @@ submodule.<name>.fetchRecurseSubmodules::
 
 submodule.<name>.ignore::
 	Defines under what circumstances "git status" and the diff family show
-	a submodule as modified. When set to "all", it will never be considered
-	modified (but it will nonetheless show up in the output of status and
-	commit when it has been staged), "dirty" will ignore all changes
-	to the submodule's work tree and
+	a submodule as modified.
+	When set to "all" will never consider the submodule modified. It can
+	nevertheless be staged using the option --force and it will then show up
+	in the output of status.
+	When set to "dirty" will ignore all changes to the submodule's work tree and
 	takes only differences between the HEAD of the submodule and the commit
 	recorded in the superproject into account. "untracked" will additionally
 	let submodules with modified tracked files in their work tree show up.
-	Using "none" (the default when this option is not set) also shows
-	submodules that have untracked files in their work tree as changed.
+	When set to "none"(default) It also show submodules as changed if they have
+	untracked files in their work tree.
 	This setting overrides any setting made in .gitmodules for this submodule,
 	both settings can be overridden on the command line by using the
 	"--ignore-submodules" option. The 'git submodule' commands are not
diff --git a/Documentation/git-add.adoc b/Documentation/git-add.adoc
index 6192daeb03..941135dc63 100644
--- a/Documentation/git-add.adoc
+++ b/Documentation/git-add.adoc
@@ -75,7 +75,10 @@ in linkgit:gitglossary[7].
 
 `-f`::
 `--force`::
-	Allow adding otherwise ignored files.
+	Allow adding otherwise ignored files. The option is also used when
+	`submodule.<name>.ignore=all` is set, but you want to stage an
+	update of the submodule. The `path` to the submodule must be explicitly
+	specified.
 
 `--sparse`::
 	Allow updating index entries outside of the sparse-checkout cone.
diff --git a/Documentation/gitmodules.adoc b/Documentation/gitmodules.adoc
index d9bec8b187..3792da96aa 100644
--- a/Documentation/gitmodules.adoc
+++ b/Documentation/gitmodules.adoc
@@ -70,7 +70,10 @@ submodule.<name>.ignore::
 --
 	all;; The submodule will never be considered modified (but will
 	    nonetheless show up in the output of status and commit when it has
-	    been staged).
+	    been staged). Add `(new commits)` can be overruled using the
+	    `git add --force <submodule.path>`.
+		The setting affects `status`, `update-index`, `diff` and `log`(due
+		to underlaying `diff`).
 
 	dirty;; All changes to the submodule's work tree will be ignored, only
 	    committed differences between the `HEAD` of the submodule and its
-- 
gitgitgadget
Junio C Hamano· Feb 9, 2026, 00:11 UTC · re: Claus Schneider(Eficode) via GitGitGadget · lore

Re: [PATCH v4 1/5] read-cache: update add_files_to_cache take param ignored_too

"Claus Schneider(Eficode) via GitGitGadget" <gitgitgadget@gmail.com> writes:

Show 7 quoted lines
> From: "Claus Schneider(Eficode)" <claus.schneider@eficode.com>
>
> The ignored_too parameter is added to the function
> add_files_to_cache for usage of explicit updating the index for the updated
> submodule using the explicit patchspec to the submodule.
>
> Signed-off-by: Claus Schneider(Eficode) <claus.schneider@eficode.com>

Not about the patch at all, and not a complaint at all, but an observation.

Your sign-off is given without a space before "(EFicode)" here, while the previous iteration has a space there. It seems that your author identity has been without the space, so this change makes it consistent between the two.

Junio C Hamano· Feb 9, 2026, 00:11 UTC · re: Claus Schneider(Eficode) via GitGitGadget · lore

Re: [PATCH v4 1/5] read-cache: update add_files_to_cache take param ignored_too

"Claus Schneider(Eficode) via GitGitGadget" <gitgitgadget@gmail.com> writes:

Show 7 quoted lines
> From: "Claus Schneider(Eficode)" <claus.schneider@eficode.com>
>
> The ignored_too parameter is added to the function
> add_files_to_cache for usage of explicit updating the index for the updated
> submodule using the explicit patchspec to the submodule.
>
> Signed-off-by: Claus Schneider(Eficode) <claus.schneider@eficode.com>

Not about the patch at all, and not a complaint at all, but an observation.

Your sign-off is given without a space before "(EFicode)" here, while the previous iteration has a space there. It seems that your author identity has been without the space, so this change makes it consistent between the two.

Junio C Hamano· Feb 20, 2026, 22:27 UTC · re: Claus Schneider via GitGitGadget · lore

Re: [PATCH v4 0/5] git-add: Skip submodules with ignore=all unless --force and explicit path used

"Claus Schneider via GitGitGadget" <gitgitgadget@gmail.com> writes:
Show 21 quoted lines
> The ignore=all configuration for submodules is currently honored by status
> and diff, but not by add. This inconsistency causes friction when working
> with submodules:
>
>  * Developers unintentionally stage submodule updates, leading to conflicts
>    and unnecessary changes.
>  * Tracking branches in submodule configs causes friction as updates to the
>    submodule SHA1 are added without intent.
>
> This patch aligns git add with the behavior of status and diff:
>
>  * Submodules marked ignore=all are skipped by default.
>  * Attempting to add such a submodule explicitly now requires --force.
>
> A submodule can frictionless track a branch in the configuration or manually
> switched to and use update --update --remote without unintentionally add the
> changes to the super-project.
>
> Tests that previously added submodules without --force have been updated
> accordingly. A new test is added to test the behavior of git add with and
> without --force.

The latest round of this series has not seen any meaningful reviews. Everybody happy with this latest round?

Thanks.
Kristoffer Haugsbakk· Mar 4, 2026, 14:01 UTC · re: Claus Schneider(Eficode) via GitGitGadget · lore

Re: [PATCH v4 5/5] Documentation: update add --force option + ignore=all config

On Fri, Feb 6, 2026, at 14:23, Claus Schneider(Eficode) via GitGitGadget wrote:
Show 15 quoted lines
> From: "Claus Schneider(Eficode)" <claus.schneider@eficode.com>
>
> - git-add.adoc: Update the --force documentation for submodule behaviour
>   to be added even the given configuration ignore=all.
> - gitmodules.adoc and config/submodule.adoc: The submodule config
>   ignore=all now need --force in order to update the index.
>
> Signed-off-by: Claus Schneider(Eficode) <claus.schneider@eficode.com>
>[snip]
>  	all;; The submodule will never be considered modified (but will
>  	    nonetheless show up in the output of status and commit when it has
> -	    been staged).
> +	    been staged). Add `(new commits)` can be overruled using the
> +	    `git add --force <submodule.path>`.
> +		The setting affects `status`, `update-index`, `diff` and `log`(due
This is in `next` but: should be a space: “`log` (due”.
> +		to underlaying `diff`).
s/underlaying/underlying/ ?
Show 5 quoted lines
>
>  	dirty;; All changes to the submodule's work tree will be ignored, only
>  	    committed differences between the `HEAD` of the submodule and its
> --
> gitgitgadget
Claus Schneider· Mar 10, 2026, 21:04 UTC · re: Kristoffer Haugsbakk · lore

Re: [PATCH v4 5/5] Documentation: update add --force option + ignore=all config

Hi ..
Thanks .. I will fix both.

Br Claus Schneider

On Wed, Mar 4, 2026 at 3:02 PM Kristoffer Haugsbakk <kristofferhaugsbakk@fastmail.com> wrote:

Show 29 quoted lines
>
> On Fri, Feb 6, 2026, at 14:23, Claus Schneider(Eficode) via GitGitGadget wrote:
> > From: "Claus Schneider(Eficode)" <claus.schneider@eficode.com>
> >
> > - git-add.adoc: Update the --force documentation for submodule behaviour
> >   to be added even the given configuration ignore=all.
> > - gitmodules.adoc and config/submodule.adoc: The submodule config
> >   ignore=all now need --force in order to update the index.
> >
> > Signed-off-by: Claus Schneider(Eficode) <claus.schneider@eficode.com>
> >[snip]
> >       all;; The submodule will never be considered modified (but will
> >           nonetheless show up in the output of status and commit when it has
> > -         been staged).
> > +         been staged). Add `(new commits)` can be overruled using the
> > +         `git add --force <submodule.path>`.
> > +             The setting affects `status`, `update-index`, `diff` and `log`(due
>
> This is in `next` but: should be a space: “`log` (due”.
>
> > +             to underlaying `diff`).
>
> s/underlaying/underlying/ ?
>
> >
> >       dirty;; All changes to the submodule's work tree will be ignored, only
> >           committed differences between the `HEAD` of the submodule and its
> > --
> > gitgitgadget
Claus Schneider· Mar 10, 2026, 21:10 UTC · re: Claus Schneider · lore

Re: [PATCH v4 5/5] Documentation: update add --force option + ignore=all config

Hi Kristoffer,

I am unsure about submitting these fixes now, as the patch appears to have already been merged.

I could add it as a 6th patch, and merging would still work fine instead of amending the 5th patch - please let me know what is the best way to proceed

Best regards, Claus Schneider

On Tue, Mar 10, 2026 at 10:04 PM Claus Schneider <claus.schneider@eficode.com> wrote:

Show 39 quoted lines
>
> Hi ..
>
> Thanks .. I will fix both.
>
> Br
> Claus Schneider
>
> On Wed, Mar 4, 2026 at 3:02 PM Kristoffer Haugsbakk
> <kristofferhaugsbakk@fastmail.com> wrote:
> >
> > On Fri, Feb 6, 2026, at 14:23, Claus Schneider(Eficode) via GitGitGadget wrote:
> > > From: "Claus Schneider(Eficode)" <claus.schneider@eficode.com>
> > >
> > > - git-add.adoc: Update the --force documentation for submodule behaviour
> > >   to be added even the given configuration ignore=all.
> > > - gitmodules.adoc and config/submodule.adoc: The submodule config
> > >   ignore=all now need --force in order to update the index.
> > >
> > > Signed-off-by: Claus Schneider(Eficode) <claus.schneider@eficode.com>
> > >[snip]
> > >       all;; The submodule will never be considered modified (but will
> > >           nonetheless show up in the output of status and commit when it has
> > > -         been staged).
> > > +         been staged). Add `(new commits)` can be overruled using the
> > > +         `git add --force <submodule.path>`.
> > > +             The setting affects `status`, `update-index`, `diff` and `log`(due
> >
> > This is in `next` but: should be a space: “`log` (due”.
> >
> > > +             to underlaying `diff`).
> >
> > s/underlaying/underlying/ ?
> >
> > >
> > >       dirty;; All changes to the submodule's work tree will be ignored, only
> > >           committed differences between the `HEAD` of the submodule and its
> > > --
> > > gitgitgadget

← back to recent threads