git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [Feature Request] Allow batch removal of remotes with 'git remote remove'
@ 2025-01-20 23:06 Christian Fredrik Johnsen
  2025-01-21 21:10 ` Emily Shaffer
  0 siblings, 1 reply; 8+ messages in thread
From: Christian Fredrik Johnsen @ 2025-01-20 23:06 UTC (permalink / raw)
  To: git@vger.kernel.org


[-- Attachment #1.1: Type: text/plain, Size: 1461 bytes --]

Hello 😃

I would like to propose a feature enhancement to the 'git remote remove' command.

--- The Problem ---
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:

`git remote remove remote1 remote2 remote3`

This would simplify workflows for repositories with multiple remotes when clean-up operations are needed.

--- Proposed Solution ---
Modify the 'git remote remove' command to accept multiple remote names as arguments and remove them all in a single invocation.

For example:

`git remote remove myfork myrepo origin`

--- Benefits
- Reduces repetitive commands for users with many remotes.
- Aligns with existing batch-like behavior in commands like 'git branch -d branch1 branch2'.
- Streamlines repository maintenance, especially for power users.

Thank you for considering this request. I’d be happy to provide further details or clarification if needed.

Best regards,
Christian Fredrik Johnsen

=====================================================
---> Generated this message with ChatGPT, but it gets to the point.

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.
There are no `github issues` I can search through to find older related issues, so I'll give it a go.

Attached a picture showing the situation where I encountered the issue.

[-- Attachment #1.2: Type: text/html, Size: 6159 bytes --]

[-- Attachment #2: git-remote-remove.png --]
[-- Type: image/png, Size: 231926 bytes --]

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

* Re: [Feature Request] Allow batch removal of remotes with 'git remote remove'
  2025-01-20 23:06 [Feature Request] Allow batch removal of remotes with 'git remote remove' Christian Fredrik Johnsen
@ 2025-01-21 21:10 ` Emily Shaffer
  2025-01-21 21:32   ` D. Ben Knoble
  0 siblings, 1 reply; 8+ messages in thread
From: Emily Shaffer @ 2025-01-21 21:10 UTC (permalink / raw)
  To: Christian Fredrik Johnsen; +Cc: git@vger.kernel.org

On Mon, Jan 20, 2025 at 3:07 PM Christian Fredrik Johnsen
<cfj@johnsen.no> wrote:
>
> Hello 😃
>
> I would like to propose a feature enhancement to the 'git remote remove' command.
>
> --- The Problem ---
> 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:
>
> `git remote remove remote1 remote2 remote3`
>
> This would simplify workflows for repositories with multiple remotes when clean-up operations are needed.

Hi Christian, is there a reason why opening up the config (`vim
.git/config` or `git config edit --local`) and batch-deleting remotes
from there is undesirable? If this is a solution you believe only
power users need, then I'd posit a power user can both list all
remotes *and* remove the offending ones in a single editor pass,
rather than having to run multiple `git remote` commands, anyway.

>
> --- Proposed Solution ---
> Modify the 'git remote remove' command to accept multiple remote names as arguments and remove them all in a single invocation.
>
> For example:
>
> `git remote remove myfork myrepo origin`
>
> --- Benefits
> - Reduces repetitive commands for users with many remotes.
> - Aligns with existing batch-like behavior in commands like 'git branch -d branch1 branch2'.
> - Streamlines repository maintenance, especially for power users.
>
> Thank you for considering this request. I’d be happy to provide further details or clarification if needed.
>
> Best regards,
> Christian Fredrik Johnsen
>
> =====================================================
> ---> Generated this message with ChatGPT, but it gets to the point.
>
> 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.
> There are no `github issues` I can search through to find older related issues, so I'll give it a go.
>
> Attached a picture showing the situation where I encountered the issue.

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

* Re: [Feature Request] Allow batch removal of remotes with 'git remote remove'
  2025-01-21 21:10 ` Emily Shaffer
@ 2025-01-21 21:32   ` D. Ben Knoble
  2025-01-21 22:38     ` Junio C Hamano
  2025-01-22  2:24     ` brian m. carlson
  0 siblings, 2 replies; 8+ messages in thread
From: D. Ben Knoble @ 2025-01-21 21:32 UTC (permalink / raw)
  To: Emily Shaffer; +Cc: Christian Fredrik Johnsen, git@vger.kernel.org

On Tue, Jan 21, 2025 at 4:16 PM Emily Shaffer <nasamuffin@google.com> wrote:
>
> On Mon, Jan 20, 2025 at 3:07 PM Christian Fredrik Johnsen
> <cfj@johnsen.no> wrote:
> >
> > Hello 😃
> >
> > I would like to propose a feature enhancement to the 'git remote remove' command.
> >
> > --- The Problem ---
> > 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:
> >
> > `git remote remove remote1 remote2 remote3`
> >
> > This would simplify workflows for repositories with multiple remotes when clean-up operations are needed.
>
> Hi Christian, is there a reason why opening up the config (`vim
> .git/config` or `git config edit --local`) and batch-deleting remotes
> from there is undesirable? If this is a solution you believe only
> power users need, then I'd posit a power user can both list all
> remotes *and* remove the offending ones in a single editor pass,
> rather than having to run multiple `git remote` commands, anyway.

I'd posit a power user can also do something a bit like (Zsh with GNU
or FreeBSD xargs) `print -N my remotes to delete | xargs -0n1 git
remote remove`, or (portably) `for remote in my remotes to delete; do
git remote remove "$remote"; done`.

I couldn't find a comparable command beyond `git branch --delete`,
which _does_ take multiple branches.

-- 
D. Ben Knoble

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

* Re: [Feature Request] Allow batch removal of remotes with 'git remote remove'
  2025-01-21 21:32   ` D. Ben Knoble
@ 2025-01-21 22:38     ` Junio C Hamano
  2025-01-22  2:24     ` brian m. carlson
  1 sibling, 0 replies; 8+ messages in thread
From: Junio C Hamano @ 2025-01-21 22:38 UTC (permalink / raw)
  To: D. Ben Knoble
  Cc: Emily Shaffer, Christian Fredrik Johnsen, git@vger.kernel.org

"D. Ben Knoble" <ben.knoble@gmail.com> writes:

>> Hi Christian, is there a reason why opening up the config (`vim
>> .git/config` or `git config edit --local`) and batch-deleting remotes
>> from there is undesirable? If this is a solution you believe only
>> power users need, then I'd posit a power user can both list all
>> remotes *and* remove the offending ones in a single editor pass,
>> rather than having to run multiple `git remote` commands, anyway.
>
> I'd posit a power user can also do something a bit like (Zsh with GNU
> or FreeBSD xargs) `print -N my remotes to delete | xargs -0n1 git
> remote remove`, or (portably) `for remote in my remotes to delete; do
> git remote remove "$remote"; done`.

Having to run "git remote remove" 1000 times for 1000 remotes you
happen to have may not be the best use of machine cycles.  I'd have
to think about "git config edit --local".  If you have 1000 remotes,
the chance of mistakes may be too big, as it is likely that you
would not notice if you removed unrelated things by accident.
Besides, the remote-tracking branches are left behind if you only
used "git config edit --local".

> I couldn't find a comparable command beyond `git branch --delete`,
> which _does_ take multiple branches.

I do not offhand think of a reason why it is a bad idea to let "git
remote remove <name>" take more than one remote names (i.e. making
it "git remote remove <name>...").  Even though it may not help if
you have 1000 remotes and want to remove all of them in one go, at
least your xargs command line invocation would become less wasteful.

Thanks.


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

* Re: [Feature Request] Allow batch removal of remotes with 'git remote remove'
  2025-01-21 21:32   ` D. Ben Knoble
  2025-01-21 22:38     ` Junio C Hamano
@ 2025-01-22  2:24     ` brian m. carlson
  2025-01-22  3:08       ` Jeff King
  2025-01-22  9:40       ` Patrick Steinhardt
  1 sibling, 2 replies; 8+ messages in thread
From: brian m. carlson @ 2025-01-22  2:24 UTC (permalink / raw)
  To: D. Ben Knoble
  Cc: Emily Shaffer, Christian Fredrik Johnsen, git@vger.kernel.org

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

On 2025-01-21 at 21:32:04, D. Ben Knoble wrote:
> On Tue, Jan 21, 2025 at 4:16 PM Emily Shaffer <nasamuffin@google.com> wrote:
> >
> > Hi Christian, is there a reason why opening up the config (`vim
> > .git/config` or `git config edit --local`) and batch-deleting remotes
> > from there is undesirable? If this is a solution you believe only
> > power users need, then I'd posit a power user can both list all
> > remotes *and* remove the offending ones in a single editor pass,
> > rather than having to run multiple `git remote` commands, anyway.
> 
> I'd posit a power user can also do something a bit like (Zsh with GNU
> or FreeBSD xargs) `print -N my remotes to delete | xargs -0n1 git
> remote remove`, or (portably) `for remote in my remotes to delete; do
> git remote remove "$remote"; done`.

I agree that is possible, but it may not perform well.  I used to work
at a company where, for many years, I merged other developers' code by
hand and pushed it, which necessitated having everyone's remote. In the
main project, there were many people's feature and development branches
in their remotes, so I had well over 80,000 refs in my repository.

Because `git remote remove` will remove remote-tracking branches and
their reflogs, we typically will want to do that all at once in a single
ref transaction, and hence in one command.  Not doing so performs very
poorly (as does, notably `git remote rename`[0]) when all of the refs are
packed.  If you have a large number of remotes to delete and a large
number of total refs, this will perform really badly indeed, since the
operation of rewriting the packed-refs file becomes quadratic.

The removal of the remote-tracking branches is also the reason that
editing the config isn't sufficient, either.

So I think this feature would be useful, although I agree that for many
smaller repos, the shell script approach would be acceptable in the
interim.

[0] Sometime back I reported that `git remote rename` on a fresh clone
with 45,000 refs took about 45 minutes.  The reason I didn't choose the
remote name on the original clone (with `-o`) is because it was in a
GitHub Codespace, which had cloned it for me already.  Fortunately, this
is now down to about 55 to 78 seconds with reftable, which is a major
improvement, and I'm sure we could do better still.
-- 
brian m. carlson (they/them or he/him)
Toronto, Ontario, CA

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

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

* Re: [Feature Request] Allow batch removal of remotes with 'git remote remove'
  2025-01-22  2:24     ` brian m. carlson
@ 2025-01-22  3:08       ` Jeff King
  2025-01-22 16:23         ` Junio C Hamano
  2025-01-22  9:40       ` Patrick Steinhardt
  1 sibling, 1 reply; 8+ messages in thread
From: Jeff King @ 2025-01-22  3:08 UTC (permalink / raw)
  To: brian m. carlson
  Cc: D. Ben Knoble, Emily Shaffer, Christian Fredrik Johnsen,
	git@vger.kernel.org

On Wed, Jan 22, 2025 at 02:24:38AM +0000, brian m. carlson wrote:

> Because `git remote remove` will remove remote-tracking branches and
> their reflogs, we typically will want to do that all at once in a single
> ref transaction, and hence in one command.  Not doing so performs very
> poorly (as does, notably `git remote rename`[0]) when all of the refs are
> packed.  If you have a large number of remotes to delete and a large
> number of total refs, this will perform really badly indeed, since the
> operation of rewriting the packed-refs file becomes quadratic.
> 
> The removal of the remote-tracking branches is also the reason that
> editing the config isn't sufficient, either.

I think the config update is probably quadratic, too (in the number of
remotes). Each one is going to rewrite the whole config file, minus its
matching section. But a "remove" operation that took multiple remotes
could do it all in a single pass.

If somebody does implement "remote remove" that takes multiple names, I
hope they'll refactor to do all of the operations in a single pass, and
not just loop on builtin/remote.c:rm() internally.

Probably git-config could stand to learn similar tricks, too. There is
"--remove-section", but I don't think you can pass multiple sections
(and it's likewise quadratic).

-Peff

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

* Re: [Feature Request] Allow batch removal of remotes with 'git remote remove'
  2025-01-22  2:24     ` brian m. carlson
  2025-01-22  3:08       ` Jeff King
@ 2025-01-22  9:40       ` Patrick Steinhardt
  1 sibling, 0 replies; 8+ messages in thread
From: Patrick Steinhardt @ 2025-01-22  9:40 UTC (permalink / raw)
  To: brian m. carlson, D. Ben Knoble, Emily Shaffer,
	Christian Fredrik Johnsen, git@vger.kernel.org

On Wed, Jan 22, 2025 at 02:24:38AM +0000, brian m. carlson wrote:
> [0] Sometime back I reported that `git remote rename` on a fresh clone
> with 45,000 refs took about 45 minutes.  The reason I didn't choose the
> remote name on the original clone (with `-o`) is because it was in a
> GitHub Codespace, which had cloned it for me already.  Fortunately, this
> is now down to about 55 to 78 seconds with reftable, which is a major
> improvement, and I'm sure we could do better still.

That's awesome. Thanks a lot for playing around with reftables and
reporting your bugs and findings, I really appreciate it. This kind of
information is invaluable to us.

Patrick

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

* Re: [Feature Request] Allow batch removal of remotes with 'git remote remove'
  2025-01-22  3:08       ` Jeff King
@ 2025-01-22 16:23         ` Junio C Hamano
  0 siblings, 0 replies; 8+ messages in thread
From: Junio C Hamano @ 2025-01-22 16:23 UTC (permalink / raw)
  To: Jeff King
  Cc: brian m. carlson, D. Ben Knoble, Emily Shaffer,
	Christian Fredrik Johnsen, git@vger.kernel.org

Jeff King <peff@peff.net> writes:

> On Wed, Jan 22, 2025 at 02:24:38AM +0000, brian m. carlson wrote:
>
>> Because `git remote remove` will remove remote-tracking branches and
>> their reflogs, we typically will want to do that all at once in a single
>> ref transaction, and hence in one command.  Not doing so performs very
>> poorly (as does, notably `git remote rename`[0]) when all of the refs are
>> packed.  If you have a large number of remotes to delete and a large
>> number of total refs, this will perform really badly indeed, since the
>> operation of rewriting the packed-refs file becomes quadratic.
>> 
>> The removal of the remote-tracking branches is also the reason that
>> editing the config isn't sufficient, either.
>
> I think the config update is probably quadratic, too (in the number of
> remotes). Each one is going to rewrite the whole config file, minus its
> matching section. But a "remove" operation that took multiple remotes
> could do it all in a single pass.
>
> If somebody does implement "remote remove" that takes multiple names, I
> hope they'll refactor to do all of the operations in a single pass, and
> not just loop on builtin/remote.c:rm() internally.
>
> Probably git-config could stand to learn similar tricks, too. There is
> "--remove-section", but I don't think you can pass multiple sections
> (and it's likewise quadratic).

Thanks for bringing up the performance aspect and where the problem
lies in the current implementation.



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

end of thread, other threads:[~2025-01-22 16:23 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-01-20 23:06 [Feature Request] Allow batch removal of remotes with 'git remote remove' Christian Fredrik Johnsen
2025-01-21 21:10 ` Emily Shaffer
2025-01-21 21:32   ` D. Ben Knoble
2025-01-21 22:38     ` Junio C Hamano
2025-01-22  2:24     ` brian m. carlson
2025-01-22  3:08       ` Jeff King
2025-01-22 16:23         ` Junio C Hamano
2025-01-22  9:40       ` Patrick Steinhardt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).