threads / discuss / 23360

Getting rid of a stale remote?

Subject: Getting rid of a stale remote?

## tl;dr

5 messages between Apr 6, 2010 and Apr 9, 2010.

replies: 4people: 3as markdown or json

Tim Visher· Apr 6, 2010, 18:03 UTC · lore
Hello Everyone,

I'm trying to get rid of a stale remote. I deleted the remote via `git remote rm <remote>` and that removed it from .git/config but for some reason the references stayed in the listing of `git branch -a`.

How do I get rid of the listing in `git branch`?
-- 
In Christ,

Timmy V.

http://burningones.com/
http://five.sentenc.es/ - Spend less time on e-mail
Ramkumar Ramachandra· Apr 6, 2010, 18:07 UTC · re: Tim Visher · lore

Re: Getting rid of a stale remote?

> I'm trying to get rid of a stale remote.  I deleted the remote via
> `git remote rm <remote>` and that removed it from .git/config but for
> some reason the references stayed in the listing of `git branch -a`.
See `git remote prune`.
-- Ram
Tim Visher· Apr 6, 2010, 18:25 UTC · re: Ramkumar Ramachandra · lore

Re: Getting rid of a stale remote?

On Tue, Apr 6, 2010 at 2:07 PM, Ramkumar Ramachandra <artagnon@gmail.com> wrote:
Show 5 quoted lines
>> I'm trying to get rid of a stale remote.  I deleted the remote via
>> `git remote rm <remote>` and that removed it from .git/config but for
>> some reason the references stayed in the listing of `git branch -a`.
>
> See `git remote prune`.
From the remote man page:
>   prune
>       Deletes all stale tracking branches under <name>. These stale branches
>       have already been removed from the remote repository referenced by
>       <name>, but are still locally available in "remotes/<name>".
I'm unclear as to how this solves my problem.  Consider the following:
    $ git remote
    a
    b
    c
    $ git branch -a
    a
    b
    c
    remotes/a/branch
    remotes/b/branch
    remotes/c/branch
    remotes/d/branch
    $ git remote prune d
    fatal: 'd' does not appear to be a git repository
    fatal: The remote end hung up unexpectedly
    $ git remote rm d
    error: Could not remove config section 'remote.d'
I would like to get rid of the `remotes/d/branch` entry.
-- 
In Christ,

Timmy V.

http://burningones.com/
http://five.sentenc.es/ - Spend less time on e-mail
Jeff King· Apr 6, 2010, 18:42 UTC · re: Tim Visher · lore

Re: Getting rid of a stale remote?

On Tue, Apr 06, 2010 at 02:25:07PM -0400, Tim Visher wrote:
Show 6 quoted lines
> >   prune
> >       Deletes all stale tracking branches under <name>. These stale branches
> >       have already been removed from the remote repository referenced by
> >       <name>, but are still locally available in "remotes/<name>".
> 
> I'm unclear as to how this solves my problem.  Consider the following:

It doesn't. Prune is about removing stale branches of _existing_ remotes, but you want to remove the whole remote.

>     $ git remote
>     a
>     b
>     c
So you don't have a remote 'd' at this point.
Show 8 quoted lines
>     $ git branch -a
>     a
>     b
>     c
>     remotes/a/branch
>     remotes/b/branch
>     remotes/c/branch
>     remotes/d/branch
But you do have a crufty tracking branch.
>     $ git remote prune d
>     fatal: 'd' does not appear to be a git repository
>     fatal: The remote end hung up unexpectedly

You don't have a remote 'd', so we try to a git repository in the directory 'd'. Which obviously doesn't work.

>     $ git remote rm d
>     error: Could not remove config section 'remote.d'

And this fails because you have no configured remote 'd', just the crufty branch. How you got into that state, I don't know, but I imagine it was from deleting the config in .git/config manually instead of using "git remote rm" in the first place.

It would be tempting to say that "git remote rm" should continue if the config simply doesn't exist and remove the crufty branch, but that is not quite right. We actually need the config to tell us "here is where we store the tracking branches for remote d". Of course, unless you have munged the config manually, it will always be "refs/remotes/d". So we could perhaps guess that for the case of missing config (possibly with "git remote rm -f" or something).

But if you just want to do things manually, try "git branch -d -r d/branch".

-Peff
Tim Visher· Apr 9, 2010, 02:08 UTC · re: Jeff King · lore

Re: Getting rid of a stale remote?

On Tue, Apr 6, 2010 at 2:42 PM, Jeff King <peff@peff.net> wrote:
Show 8 quoted lines
> On Tue, Apr 06, 2010 at 02:25:07PM -0400, Tim Visher wrote:
>>     $ git remote rm d
>>     error: Could not remove config section 'remote.d'
>
> And this fails because you have no configured remote 'd', just the
> crufty branch. How you got into that state, I don't know, but I imagine
> it was from deleting the config in .git/config manually instead of using
> "git remote rm" in the first place.
%<---lengthy but almost assuredly misleading explanation of how I got there--->%

So I had this long explanation but I realized that it probably wasn't the case. If I ever run into this again I'll try to be more aware of what I did. I suspect though that it's when I want to make one remote my origin and make origin something else…

Show 7 quoted lines
> It would be tempting to say that "git remote rm" should continue if the
> config simply doesn't exist and remove the crufty branch, but that is
> not quite right. We actually need the config to tell us "here is where
> we store the tracking branches for remote d". Of course, unless you have
> munged the config manually, it will always be "refs/remotes/d". So we
> could perhaps guess that for the case of missing config (possibly with
> "git remote rm -f" or something).
That sounds quite sensible to me.  Also, a message along the lines of:
    You are trying to delete a remote for which there is no config section.  (We
    discovered a remote X in refs/remotes/X) and deleted it.|No remote X in
    refs/remotes/X. Did you store it elsewhere?)  In the future, use `git
    remote` to alter your remotes
> But if you just want to do things manually, try "git branch -d -r
> d/branch".
That did indeed work like a charm.  Thanks so much.
-- 
In Christ,

Timmy V.

http://burningones.com/
http://five.sentenc.es/ - Spend less time on e-mail

← back to recent threads