{"thread":{"id":"62836","subject":"[Feature Request] Allow batch removal of remotes with 'git remote remove'","startedAt":"2025-01-20T23:06:35Z","lastAt":"2025-01-22T16:23:13Z","messageCount":8,"participants":["Christian Fredrik Johnsen","Emily Shaffer","D. Ben Knoble","Junio C Hamano","brian m. carlson","Jeff King","Patrick Steinhardt"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"510982","messageId":"DB9PR05MB110863344D3776D13B436F563C1E72@DB9PR05MB11086.eurprd05.prod.outlook.com","threadId":"62836","inReplyTo":null,"subject":"[Feature Request] Allow batch removal of remotes with 'git remote remove'","fromName":"Christian Fredrik Johnsen","fromEmail":"cfj@johnsen.no","sentAt":"2025-01-20T23:06:32Z","receivedAt":"2025-01-20T23:06:35Z","isPatch":false,"sender":{"key":"cfj@johnsen.no","avatar":null},"body":"Hello 😃\n\nI would like to propose a feature enhancement to the 'git remote remove' command.\n\n--- The Problem ---\nCurrently, 'git remote remove' only supports removing one remote at a time. However, it would be useful to allow batch removal of remotes, as in:\n\n`git remote remove remote1 remote2 remote3`\n\nThis would simplify workflows for repositories with multiple remotes when clean-up operations are needed.\n\n--- Proposed Solution ---\nModify the 'git remote remove' command to accept multiple remote names as arguments and remove them all in a single invocation.\n\nFor example:\n\n`git remote remove myfork myrepo origin`\n\n--- Benefits\n- Reduces repetitive commands for users with many remotes.\n- Aligns with existing batch-like behavior in commands like 'git branch -d branch1 branch2'.\n- Streamlines repository maintenance, especially for power users.\n\nThank you for considering this request. I’d be happy to provide further details or clarification if needed.\n\nBest regards,\nChristian Fredrik Johnsen\n\n=====================================================\n---> Generated this message with ChatGPT, but it gets to the point.\n\nI am assuming that this is such a niche case that it hasn't been reported yet, though please correct me if I am wrong.\nThere are no `github issues` I can search through to find older related issues, so I'll give it a go.\n\nAttached a picture showing the situation where I encountered the issue.\n"},{"id":"511022","messageId":"CAJoAoZnecm5y8243R9JsGjRDuv-Mb=UAwa+Hbj5CKDKNPBLB4g@mail.gmail.com","threadId":"62836","inReplyTo":"DB9PR05MB110863344D3776D13B436F563C1E72@DB9PR05MB11086.eurprd05.prod.outlook.com","subject":"Re: [Feature Request] Allow batch removal of remotes with 'git remote remove'","fromName":"Emily Shaffer","fromEmail":"nasamuffin@google.com","sentAt":"2025-01-21T21:10:33Z","receivedAt":"2025-01-21T21:10:45Z","isPatch":false,"sender":{"key":"nasamuffin@google.com","avatar":"https://avatars.githubusercontent.com/u/1606826?v=4"},"body":"On Mon, Jan 20, 2025 at 3:07 PM Christian Fredrik Johnsen\n<cfj@johnsen.no> wrote:\n>\n> Hello 😃\n>\n> I would like to propose a feature enhancement to the 'git remote remove' command.\n>\n> --- The Problem ---\n> Currently, 'git remote remove' only supports removing one remote at a time. However, it would be useful to allow batch removal of remotes, as in:\n>\n> `git remote remove remote1 remote2 remote3`\n>\n> This would simplify workflows for repositories with multiple remotes when clean-up operations are needed.\n\nHi Christian, is there a reason why opening up the config (`vim\n.git/config` or `git config edit --local`) and batch-deleting remotes\nfrom there is undesirable? If this is a solution you believe only\npower users need, then I'd posit a power user can both list all\nremotes *and* remove the offending ones in a single editor pass,\nrather than having to run multiple `git remote` commands, anyway.\n\n>\n> --- Proposed Solution ---\n> Modify the 'git remote remove' command to accept multiple remote names as arguments and remove them all in a single invocation.\n>\n> For example:\n>\n> `git remote remove myfork myrepo origin`\n>\n> --- Benefits\n> - Reduces repetitive commands for users with many remotes.\n> - Aligns with existing batch-like behavior in commands like 'git branch -d branch1 branch2'.\n> - Streamlines repository maintenance, especially for power users.\n>\n> Thank you for considering this request. I’d be happy to provide further details or clarification if needed.\n>\n> Best regards,\n> Christian Fredrik Johnsen\n>\n> =====================================================\n> ---> Generated this message with ChatGPT, but it gets to the point.\n>\n> I am assuming that this is such a niche case that it hasn't been reported yet, though please correct me if I am wrong.\n> There are no `github issues` I can search through to find older related issues, so I'll give it a go.\n>\n> Attached a picture showing the situation where I encountered the issue.\n"},{"id":"511024","messageId":"CALnO6CAEaOUNwMpOTF8wKVd7LAv+UiU5W62ZCBc0U-K_JhHU-g@mail.gmail.com","threadId":"62836","inReplyTo":"CAJoAoZnecm5y8243R9JsGjRDuv-Mb=UAwa+Hbj5CKDKNPBLB4g@mail.gmail.com","subject":"Re: [Feature Request] Allow batch removal of remotes with 'git remote remove'","fromName":"D. Ben Knoble","fromEmail":"ben.knoble@gmail.com","sentAt":"2025-01-21T21:32:04Z","receivedAt":"2025-01-21T21:32:17Z","isPatch":false,"sender":{"key":"ben.knoble@gmail.com","avatar":"https://avatars.githubusercontent.com/u/22802209?v=4"},"body":"On Tue, Jan 21, 2025 at 4:16 PM Emily Shaffer <nasamuffin@google.com> wrote:\n>\n> On Mon, Jan 20, 2025 at 3:07 PM Christian Fredrik Johnsen\n> <cfj@johnsen.no> wrote:\n> >\n> > Hello 😃\n> >\n> > I would like to propose a feature enhancement to the 'git remote remove' command.\n> >\n> > --- The Problem ---\n> > Currently, 'git remote remove' only supports removing one remote at a time. However, it would be useful to allow batch removal of remotes, as in:\n> >\n> > `git remote remove remote1 remote2 remote3`\n> >\n> > This would simplify workflows for repositories with multiple remotes when clean-up operations are needed.\n>\n> Hi Christian, is there a reason why opening up the config (`vim\n> .git/config` or `git config edit --local`) and batch-deleting remotes\n> from there is undesirable? If this is a solution you believe only\n> power users need, then I'd posit a power user can both list all\n> remotes *and* remove the offending ones in a single editor pass,\n> rather than having to run multiple `git remote` commands, anyway.\n\nI'd posit a power user can also do something a bit like (Zsh with GNU\nor FreeBSD xargs) `print -N my remotes to delete | xargs -0n1 git\nremote remove`, or (portably) `for remote in my remotes to delete; do\ngit remote remove \"$remote\"; done`.\n\nI couldn't find a comparable command beyond `git branch --delete`,\nwhich _does_ take multiple branches.\n\n-- \nD. Ben Knoble\n"},{"id":"511028","messageId":"xmqqikq7yepr.fsf@gitster.g","threadId":"62836","inReplyTo":"CALnO6CAEaOUNwMpOTF8wKVd7LAv+UiU5W62ZCBc0U-K_JhHU-g@mail.gmail.com","subject":"Re: [Feature Request] Allow batch removal of remotes with 'git remote remove'","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2025-01-21T22:38:56Z","receivedAt":"2025-01-21T22:38:59Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"D. Ben Knoble\" <ben.knoble@gmail.com> writes:\n\n>> Hi Christian, is there a reason why opening up the config (`vim\n>> .git/config` or `git config edit --local`) and batch-deleting remotes\n>> from there is undesirable? If this is a solution you believe only\n>> power users need, then I'd posit a power user can both list all\n>> remotes *and* remove the offending ones in a single editor pass,\n>> rather than having to run multiple `git remote` commands, anyway.\n>\n> I'd posit a power user can also do something a bit like (Zsh with GNU\n> or FreeBSD xargs) `print -N my remotes to delete | xargs -0n1 git\n> remote remove`, or (portably) `for remote in my remotes to delete; do\n> git remote remove \"$remote\"; done`.\n\nHaving to run \"git remote remove\" 1000 times for 1000 remotes you\nhappen to have may not be the best use of machine cycles.  I'd have\nto think about \"git config edit --local\".  If you have 1000 remotes,\nthe chance of mistakes may be too big, as it is likely that you\nwould not notice if you removed unrelated things by accident.\nBesides, the remote-tracking branches are left behind if you only\nused \"git config edit --local\".\n\n> I couldn't find a comparable command beyond `git branch --delete`,\n> which _does_ take multiple branches.\n\nI do not offhand think of a reason why it is a bad idea to let \"git\nremote remove <name>\" take more than one remote names (i.e. making\nit \"git remote remove <name>...\").  Even though it may not help if\nyou have 1000 remotes and want to remove all of them in one go, at\nleast your xargs command line invocation would become less wasteful.\n\nThanks.\n\n"},{"id":"511033","messageId":"Z5BW5ofJVbM1obb5@tapette.crustytoothpaste.net","threadId":"62836","inReplyTo":"CALnO6CAEaOUNwMpOTF8wKVd7LAv+UiU5W62ZCBc0U-K_JhHU-g@mail.gmail.com","subject":"Re: [Feature Request] Allow batch removal of remotes with 'git remote remove'","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2025-01-22T02:24:38Z","receivedAt":"2025-01-22T02:24:40Z","isPatch":false,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"On 2025-01-21 at 21:32:04, D. Ben Knoble wrote:\n> On Tue, Jan 21, 2025 at 4:16 PM Emily Shaffer <nasamuffin@google.com> wrote:\n> >\n> > Hi Christian, is there a reason why opening up the config (`vim\n> > .git/config` or `git config edit --local`) and batch-deleting remotes\n> > from there is undesirable? If this is a solution you believe only\n> > power users need, then I'd posit a power user can both list all\n> > remotes *and* remove the offending ones in a single editor pass,\n> > rather than having to run multiple `git remote` commands, anyway.\n> \n> I'd posit a power user can also do something a bit like (Zsh with GNU\n> or FreeBSD xargs) `print -N my remotes to delete | xargs -0n1 git\n> remote remove`, or (portably) `for remote in my remotes to delete; do\n> git remote remove \"$remote\"; done`.\n\nI agree that is possible, but it may not perform well.  I used to work\nat a company where, for many years, I merged other developers' code by\nhand and pushed it, which necessitated having everyone's remote. In the\nmain project, there were many people's feature and development branches\nin their remotes, so I had well over 80,000 refs in my repository.\n\nBecause `git remote remove` will remove remote-tracking branches and\ntheir reflogs, we typically will want to do that all at once in a single\nref transaction, and hence in one command.  Not doing so performs very\npoorly (as does, notably `git remote rename`[0]) when all of the refs are\npacked.  If you have a large number of remotes to delete and a large\nnumber of total refs, this will perform really badly indeed, since the\noperation of rewriting the packed-refs file becomes quadratic.\n\nThe removal of the remote-tracking branches is also the reason that\nediting the config isn't sufficient, either.\n\nSo I think this feature would be useful, although I agree that for many\nsmaller repos, the shell script approach would be acceptable in the\ninterim.\n\n[0] Sometime back I reported that `git remote rename` on a fresh clone\nwith 45,000 refs took about 45 minutes.  The reason I didn't choose the\nremote name on the original clone (with `-o`) is because it was in a\nGitHub Codespace, which had cloned it for me already.  Fortunately, this\nis now down to about 55 to 78 seconds with reftable, which is a major\nimprovement, and I'm sure we could do better still.\n-- \nbrian m. carlson (they/them or he/him)\nToronto, Ontario, CA\n"},{"id":"511034","messageId":"20250122030832.GA3322144@coredump.intra.peff.net","threadId":"62836","inReplyTo":"Z5BW5ofJVbM1obb5@tapette.crustytoothpaste.net","subject":"Re: [Feature Request] Allow batch removal of remotes with 'git remote remove'","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2025-01-22T03:08:32Z","receivedAt":"2025-01-22T03:08:33Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Wed, Jan 22, 2025 at 02:24:38AM +0000, brian m. carlson wrote:\n\n> Because `git remote remove` will remove remote-tracking branches and\n> their reflogs, we typically will want to do that all at once in a single\n> ref transaction, and hence in one command.  Not doing so performs very\n> poorly (as does, notably `git remote rename`[0]) when all of the refs are\n> packed.  If you have a large number of remotes to delete and a large\n> number of total refs, this will perform really badly indeed, since the\n> operation of rewriting the packed-refs file becomes quadratic.\n> \n> The removal of the remote-tracking branches is also the reason that\n> editing the config isn't sufficient, either.\n\nI think the config update is probably quadratic, too (in the number of\nremotes). Each one is going to rewrite the whole config file, minus its\nmatching section. But a \"remove\" operation that took multiple remotes\ncould do it all in a single pass.\n\nIf somebody does implement \"remote remove\" that takes multiple names, I\nhope they'll refactor to do all of the operations in a single pass, and\nnot just loop on builtin/remote.c:rm() internally.\n\nProbably git-config could stand to learn similar tricks, too. There is\n\"--remove-section\", but I don't think you can pass multiple sections\n(and it's likewise quadratic).\n\n-Peff\n"},{"id":"511045","messageId":"Z5C9AcABPMz6OFRd@pks.im","threadId":"62836","inReplyTo":"Z5BW5ofJVbM1obb5@tapette.crustytoothpaste.net","subject":"Re: [Feature Request] Allow batch removal of remotes with 'git remote remove'","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2025-01-22T09:40:17Z","receivedAt":"2025-01-22T09:40:27Z","isPatch":false,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"On Wed, Jan 22, 2025 at 02:24:38AM +0000, brian m. carlson wrote:\n> [0] Sometime back I reported that `git remote rename` on a fresh clone\n> with 45,000 refs took about 45 minutes.  The reason I didn't choose the\n> remote name on the original clone (with `-o`) is because it was in a\n> GitHub Codespace, which had cloned it for me already.  Fortunately, this\n> is now down to about 55 to 78 seconds with reftable, which is a major\n> improvement, and I'm sure we could do better still.\n\nThat's awesome. Thanks a lot for playing around with reftables and\nreporting your bugs and findings, I really appreciate it. This kind of\ninformation is invaluable to us.\n\nPatrick\n"},{"id":"511072","messageId":"xmqqed0uyg0i.fsf@gitster.g","threadId":"62836","inReplyTo":"20250122030832.GA3322144@coredump.intra.peff.net","subject":"Re: [Feature Request] Allow batch removal of remotes with 'git remote remove'","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2025-01-22T16:23:09Z","receivedAt":"2025-01-22T16:23:13Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jeff King <peff@peff.net> writes:\n\n> On Wed, Jan 22, 2025 at 02:24:38AM +0000, brian m. carlson wrote:\n>\n>> Because `git remote remove` will remove remote-tracking branches and\n>> their reflogs, we typically will want to do that all at once in a single\n>> ref transaction, and hence in one command.  Not doing so performs very\n>> poorly (as does, notably `git remote rename`[0]) when all of the refs are\n>> packed.  If you have a large number of remotes to delete and a large\n>> number of total refs, this will perform really badly indeed, since the\n>> operation of rewriting the packed-refs file becomes quadratic.\n>> \n>> The removal of the remote-tracking branches is also the reason that\n>> editing the config isn't sufficient, either.\n>\n> I think the config update is probably quadratic, too (in the number of\n> remotes). Each one is going to rewrite the whole config file, minus its\n> matching section. But a \"remove\" operation that took multiple remotes\n> could do it all in a single pass.\n>\n> If somebody does implement \"remote remove\" that takes multiple names, I\n> hope they'll refactor to do all of the operations in a single pass, and\n> not just loop on builtin/remote.c:rm() internally.\n>\n> Probably git-config could stand to learn similar tricks, too. There is\n> \"--remove-section\", but I don't think you can pass multiple sections\n> (and it's likewise quadratic).\n\nThanks for bringing up the performance aspect and where the problem\nlies in the current implementation.\n\n\n"}]}