* Option for "git submodule foreach" to also run on the parent git?
@ 2026-03-09 12:52 Florian Schmidt
2026-03-09 15:15 ` Junio C Hamano
2026-03-09 22:14 ` D. Ben Knoble
0 siblings, 2 replies; 6+ messages in thread
From: Florian Schmidt @ 2026-03-09 12:52 UTC (permalink / raw)
To: git
Hey everyone,
would there be an appetite for a new option to "git submodule foreach"
to run the foreach command on the parent git repo as well?
I occasionally use "git submodule foreach", for example, to make dev
branches on all the submodules if I expect to touch them all during a
dev cycle. Even if I don't need them on all submodule, once I'm done
with everything, I might run something like "git submodule foreach 'git
branch -d <foo> || :'" for easy cleanup.
In either case, I likely also want to run the same command on the parent
git. That's easily achieved by just running it manually one more time,
and I'm sure it's not hard to make a git alias for that either. But I
wonder whether the workflow is common enough that there's interest in
adding a command-line option for that? I'd be happy to have a look in
that case.
Also, tangentially related, "|| :" works, but what about a command line
option to continue on non-zero return values and not abort?
Cheers,
Florian
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Option for "git submodule foreach" to also run on the parent git?
2026-03-09 12:52 Option for "git submodule foreach" to also run on the parent git? Florian Schmidt
@ 2026-03-09 15:15 ` Junio C Hamano
2026-03-09 17:43 ` Florian Schmidt
2026-03-09 22:14 ` D. Ben Knoble
1 sibling, 1 reply; 6+ messages in thread
From: Junio C Hamano @ 2026-03-09 15:15 UTC (permalink / raw)
To: Florian Schmidt; +Cc: git
Florian Schmidt <flosch@nutanix.com> writes:
> would there be an appetite for a new option to "git submodule foreach"
> to run the foreach command on the parent git repo as well?
Not from me. After all, the top-level superproject is not a
submodule from the point of view of the tree, is it? If it were
"git submodule-and-superproject foreach", then perhaps, but at that
point, wouldn't it be simpler to explain what you are doing as
do-this . ;# do it here
git submodule foreach do-this ;# do it there all over
instead?
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Option for "git submodule foreach" to also run on the parent git?
2026-03-09 15:15 ` Junio C Hamano
@ 2026-03-09 17:43 ` Florian Schmidt
2026-03-09 19:30 ` Jeff King
0 siblings, 1 reply; 6+ messages in thread
From: Florian Schmidt @ 2026-03-09 17:43 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git
On 2026-03-09 15:15, Junio C Hamano wrote:
> Florian Schmidt <flosch@nutanix.com> writes:
>
>> would there be an appetite for a new option to "git submodule foreach"
>> to run the foreach command on the parent git repo as well?
>
> Not from me. After all, the top-level superproject is not a
> submodule from the point of view of the tree, is it? If it were
> "git submodule-and-superproject foreach", then perhaps,
True, I was thinking that, but figured an option such as "--also-parent"
would be sufficiently clear as to what's happening. But I can see that
it's maybe pretty niche and potentially confusing.
> but at that
> point, wouldn't it be simpler to explain what you are doing as
>
> do-this . ;# do it here
> git submodule foreach do-this ;# do it there all over
That's basically what's I'm doing. I figured instead of doing "foo &&
git submodule foreach foo", a "git submodule foreach --also-parent foo"
would be marginally neater. But I don't feel strongly about it.
Cheers,
Florian
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Option for "git submodule foreach" to also run on the parent git?
2026-03-09 17:43 ` Florian Schmidt
@ 2026-03-09 19:30 ` Jeff King
2026-03-09 21:03 ` brian m. carlson
0 siblings, 1 reply; 6+ messages in thread
From: Jeff King @ 2026-03-09 19:30 UTC (permalink / raw)
To: Florian Schmidt; +Cc: Derrick Stolee, Junio C Hamano, git
On Mon, Mar 09, 2026 at 05:43:14PM +0000, Florian Schmidt wrote:
> > but at that
> > point, wouldn't it be simpler to explain what you are doing as
> >
> > do-this . ;# do it here
> > git submodule foreach do-this ;# do it there all over
>
> That's basically what's I'm doing. I figured instead of doing "foo && git
> submodule foreach foo", a "git submodule foreach --also-parent foo" would be
> marginally neater. But I don't feel strongly about it.
These days we also have git-for-each-repo. It is primarily about running
a command in a set of otherwise unrelated repos. But I wonder if:
git for-each-repo --submodules do-this
would be a natural fit as an alternative to "git submodule foreach"? And
then you can imagine a "--current" option to discover the current repo
and include it in the list. And then:
git for-each-repo --submodules --current do-this
would do what you want.
I dunno. I do not have any need for this myself, but just thinking out
loud.
-Peff
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Option for "git submodule foreach" to also run on the parent git?
2026-03-09 19:30 ` Jeff King
@ 2026-03-09 21:03 ` brian m. carlson
0 siblings, 0 replies; 6+ messages in thread
From: brian m. carlson @ 2026-03-09 21:03 UTC (permalink / raw)
To: Jeff King; +Cc: Florian Schmidt, Derrick Stolee, Junio C Hamano, git
[-- Attachment #1: Type: text/plain, Size: 1182 bytes --]
On 2026-03-09 at 19:30:01, Jeff King wrote:
> These days we also have git-for-each-repo. It is primarily about running
> a command in a set of otherwise unrelated repos. But I wonder if:
>
> git for-each-repo --submodules do-this
>
> would be a natural fit as an alternative to "git submodule foreach"? And
> then you can imagine a "--current" option to discover the current repo
> and include it in the list. And then:
>
> git for-each-repo --submodules --current do-this
>
> would do what you want.
>
> I dunno. I do not have any need for this myself, but just thinking out
> loud.
I think this would be quite useful especially if it could operate on
submodules before the parent repository. My particular use case is with
the SHA-256/SHA-1 interoperability work, since that would allow people
to recursively convert submodules into interoperability mode and then
the main repository (which needs the submodule mappings first). This
seems like a thing others will want to do as well.
So while I'm not planning to work on this myself, I think this would be
a fantastic feature to add.
--
brian m. carlson (they/them)
Toronto, Ontario, CA
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 262 bytes --]
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Option for "git submodule foreach" to also run on the parent git?
2026-03-09 12:52 Option for "git submodule foreach" to also run on the parent git? Florian Schmidt
2026-03-09 15:15 ` Junio C Hamano
@ 2026-03-09 22:14 ` D. Ben Knoble
1 sibling, 0 replies; 6+ messages in thread
From: D. Ben Knoble @ 2026-03-09 22:14 UTC (permalink / raw)
To: Florian Schmidt; +Cc: git, Junio C Hamano, Jeff King, brian m . carlson
On Mon, Mar 9, 2026 at 8:56 AM Florian Schmidt <flosch@nutanix.com> wrote:
>
> Hey everyone,
>
> would there be an appetite for a new option to "git submodule foreach"
> to run the foreach command on the parent git repo as well?
>
> I occasionally use "git submodule foreach", for example, to make dev
> branches on all the submodules if I expect to touch them all during a
> dev cycle. Even if I don't need them on all submodule, once I'm done
> with everything, I might run something like "git submodule foreach 'git
> branch -d <foo> || :'" for easy cleanup.
>
> In either case, I likely also want to run the same command on the parent
> git. That's easily achieved by just running it manually one more time,
> and I'm sure it's not hard to make a git alias for that either. But I
> wonder whether the workflow is common enough that there's interest in
> adding a command-line option for that? I'd be happy to have a look in
> that case.
>
> Also, tangentially related, "|| :" works, but what about a command line
> option to continue on non-zero return values and not abort?
>
> Cheers,
> Florian
This is not particularly general-purpose, but don't we have
submodule.recurse (-> switch, checkout) and
submodule.propagateBranches to make this kind of branching workflow
easier?
--
D. Ben Knoble
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-03-09 22:14 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-09 12:52 Option for "git submodule foreach" to also run on the parent git? Florian Schmidt
2026-03-09 15:15 ` Junio C Hamano
2026-03-09 17:43 ` Florian Schmidt
2026-03-09 19:30 ` Jeff King
2026-03-09 21:03 ` brian m. carlson
2026-03-09 22:14 ` D. Ben Knoble
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox