{"thread":{"id":"65175","subject":"Option for \"git submodule foreach\" to also run on the parent git?","startedAt":"2026-03-09T12:52:12Z","lastAt":"2026-03-09T22:14:47Z","messageCount":6,"participants":["Florian Schmidt","Junio C Hamano","Jeff King","brian m. carlson","D. Ben Knoble"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"538262","messageId":"032a7767-2350-4312-a7b1-75080519c72a@nutanix.com","threadId":"65175","inReplyTo":null,"subject":"Option for \"git submodule foreach\" to also run on the parent git?","fromName":"Florian Schmidt","fromEmail":"flosch@nutanix.com","sentAt":"2026-03-09T12:52:04Z","receivedAt":"2026-03-09T12:52:12Z","isPatch":false,"sender":{"key":"flosch@nutanix.com","avatar":"https://avatars.githubusercontent.com/u/25348638?v=4"},"body":"Hey everyone,\n\nwould there be an appetite for a new option to \"git submodule foreach\" \nto run the foreach command on the parent git repo as well?\n\nI occasionally use \"git submodule foreach\", for example, to make dev \nbranches on all the submodules if I expect to touch them all during a \ndev cycle. Even if I don't need them on all submodule, once I'm done \nwith everything, I might run something like \"git submodule foreach 'git \nbranch -d <foo> || :'\" for easy cleanup.\n\nIn either case, I likely also want to run the same command on the parent \ngit. That's easily achieved by just running it manually one more time, \nand I'm sure it's not hard to make a git alias for that either. But I \nwonder whether the workflow is common enough that there's interest in \nadding a command-line option for that? I'd be happy to have a look in \nthat case.\n\nAlso, tangentially related, \"|| :\" works, but what about a command line \noption to continue on non-zero return values and not abort?\n\nCheers,\nFlorian\n"},{"id":"538287","messageId":"xmqqsea9591f.fsf@gitster.g","threadId":"65175","inReplyTo":"032a7767-2350-4312-a7b1-75080519c72a@nutanix.com","subject":"Re: Option for \"git submodule foreach\" to also run on the parent git?","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-03-09T15:15:08Z","receivedAt":"2026-03-09T15:15:11Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Florian Schmidt <flosch@nutanix.com> writes:\n\n> would there be an appetite for a new option to \"git submodule foreach\" \n> to run the foreach command on the parent git repo as well?\n\nNot from me.  After all, the top-level superproject is not a\nsubmodule from the point of view of the tree, is it?  If it were\n\"git submodule-and-superproject foreach\", then perhaps, but at that\npoint, wouldn't it be simpler to explain what you are doing as\n\n    do-this . ;# do it here\n    git submodule foreach do-this ;# do it there all over\n\ninstead?\n"},{"id":"538304","messageId":"66419a04-67b0-4b60-bf23-078cf92b2c04@nutanix.com","threadId":"65175","inReplyTo":"xmqqsea9591f.fsf@gitster.g","subject":"Re: Option for \"git submodule foreach\" to also run on the parent git?","fromName":"Florian Schmidt","fromEmail":"flosch@nutanix.com","sentAt":"2026-03-09T17:43:14Z","receivedAt":"2026-03-09T17:43:26Z","isPatch":false,"sender":{"key":"flosch@nutanix.com","avatar":"https://avatars.githubusercontent.com/u/25348638?v=4"},"body":"\n\nOn 2026-03-09 15:15, Junio C Hamano wrote:\n> Florian Schmidt <flosch@nutanix.com> writes:\n> \n>> would there be an appetite for a new option to \"git submodule foreach\"\n>> to run the foreach command on the parent git repo as well?\n> \n> Not from me.  After all, the top-level superproject is not a\n> submodule from the point of view of the tree, is it?  If it were\n> \"git submodule-and-superproject foreach\", then perhaps,\n\nTrue, I was thinking that, but figured an option such as \"--also-parent\" \nwould be sufficiently clear as to what's happening. But I can see that \nit's maybe pretty niche and potentially confusing.\n\n\n> but at that\n> point, wouldn't it be simpler to explain what you are doing as\n> \n>      do-this . ;# do it here\n>      git submodule foreach do-this ;# do it there all over\n\nThat's basically what's I'm doing. I figured instead of doing \"foo && \ngit submodule foreach foo\", a \"git submodule foreach --also-parent foo\" \nwould be marginally neater. But I don't feel strongly about it.\n\nCheers,\nFlorian\n"},{"id":"538313","messageId":"20260309193001.GD309867@coredump.intra.peff.net","threadId":"65175","inReplyTo":"66419a04-67b0-4b60-bf23-078cf92b2c04@nutanix.com","subject":"Re: Option for \"git submodule foreach\" to also run on the parent git?","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2026-03-09T19:30:01Z","receivedAt":"2026-03-09T19:30:06Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Mon, Mar 09, 2026 at 05:43:14PM +0000, Florian Schmidt wrote:\n\n> > but at that\n> > point, wouldn't it be simpler to explain what you are doing as\n> > \n> >      do-this . ;# do it here\n> >      git submodule foreach do-this ;# do it there all over\n> \n> That's basically what's I'm doing. I figured instead of doing \"foo && git\n> submodule foreach foo\", a \"git submodule foreach --also-parent foo\" would be\n> marginally neater. But I don't feel strongly about it.\n\nThese days we also have git-for-each-repo. It is primarily about running\na command in a set of otherwise unrelated repos. But I wonder if:\n\n  git for-each-repo --submodules do-this\n\nwould be a natural fit as an alternative to \"git submodule foreach\"? And\nthen you can imagine a \"--current\" option to discover the current repo\nand include it in the list. And then:\n\n  git for-each-repo --submodules --current do-this\n\nwould do what you want.\n\nI dunno. I do not have any need for this myself, but just thinking out\nloud.\n\n-Peff\n"},{"id":"538319","messageId":"aa81ivufua5uJ4nb@fruit.crustytoothpaste.net","threadId":"65175","inReplyTo":"20260309193001.GD309867@coredump.intra.peff.net","subject":"Re: Option for \"git submodule foreach\" to also run on the parent git?","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2026-03-09T21:03:06Z","receivedAt":"2026-03-09T21:03:14Z","isPatch":false,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"On 2026-03-09 at 19:30:01, Jeff King wrote:\n> These days we also have git-for-each-repo. It is primarily about running\n> a command in a set of otherwise unrelated repos. But I wonder if:\n> \n>   git for-each-repo --submodules do-this\n> \n> would be a natural fit as an alternative to \"git submodule foreach\"? And\n> then you can imagine a \"--current\" option to discover the current repo\n> and include it in the list. And then:\n> \n>   git for-each-repo --submodules --current do-this\n> \n> would do what you want.\n> \n> I dunno. I do not have any need for this myself, but just thinking out\n> loud.\n\nI think this would be quite useful especially if it could operate on\nsubmodules before the parent repository.  My particular use case is with\nthe SHA-256/SHA-1 interoperability work, since that would allow people\nto recursively convert submodules into interoperability mode and then\nthe main repository (which needs the submodule mappings first).  This\nseems like a thing others will want to do as well.\n\nSo while I'm not planning to work on this myself, I think this would be\na fantastic feature to add.\n-- \nbrian m. carlson (they/them)\nToronto, Ontario, CA\n"},{"id":"538326","messageId":"CALnO6CCR1BioeC_eYCBt9BCrFS63L6f_5p2nTk=Z9eOAj3hW1A@mail.gmail.com","threadId":"65175","inReplyTo":"032a7767-2350-4312-a7b1-75080519c72a@nutanix.com","subject":"Re: Option for \"git submodule foreach\" to also run on the parent git?","fromName":"D. Ben Knoble","fromEmail":"ben.knoble@gmail.com","sentAt":"2026-03-09T22:14:33Z","receivedAt":"2026-03-09T22:14:47Z","isPatch":false,"sender":{"key":"ben.knoble@gmail.com","avatar":"https://avatars.githubusercontent.com/u/22802209?v=4"},"body":"On Mon, Mar 9, 2026 at 8:56 AM Florian Schmidt <flosch@nutanix.com> wrote:\n>\n> Hey everyone,\n>\n> would there be an appetite for a new option to \"git submodule foreach\"\n> to run the foreach command on the parent git repo as well?\n>\n> I occasionally use \"git submodule foreach\", for example, to make dev\n> branches on all the submodules if I expect to touch them all during a\n> dev cycle. Even if I don't need them on all submodule, once I'm done\n> with everything, I might run something like \"git submodule foreach 'git\n> branch -d <foo> || :'\" for easy cleanup.\n>\n> In either case, I likely also want to run the same command on the parent\n> git. That's easily achieved by just running it manually one more time,\n> and I'm sure it's not hard to make a git alias for that either. But I\n> wonder whether the workflow is common enough that there's interest in\n> adding a command-line option for that? I'd be happy to have a look in\n> that case.\n>\n> Also, tangentially related, \"|| :\" works, but what about a command line\n> option to continue on non-zero return values and not abort?\n>\n> Cheers,\n> Florian\n\nThis is not particularly general-purpose, but don't we have\nsubmodule.recurse (-> switch, checkout) and\nsubmodule.propagateBranches to make this kind of branching workflow\neasier?\n\n-- \nD. Ben Knoble\n"}]}