# Getting rid of a stale remote?

5 messages from 2010-04-06 to 2010-04-09. Participants: Tim Visher, Ramkumar Ramachandra, Jeff King.
Thread: https://gitlist.dev/t/23360

## Tim Visher, 2010-04-06 18:03

Subject: Getting rid of a stale remote?
Message-ID: <x2jc115fd3c1004061103z3154b6b3ge34493260f12925e@mail.gmail.com>
URL: https://gitlist.dev/e/x2jc115fd3c1004061103z3154b6b3ge34493260f12925e%40mail.gmail.com

```
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, 2010-04-06 18:07

Subject: Re: Getting rid of a stale remote?
Message-ID: <w2if3271551004061107rb25b83b9p19a284f19e7d4f87@mail.gmail.com>
URL: https://gitlist.dev/e/w2if3271551004061107rb25b83b9p19a284f19e7d4f87%40mail.gmail.com
In-Reply-To: <x2jc115fd3c1004061103z3154b6b3ge34493260f12925e@mail.gmail.com>

```
> 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, 2010-04-06 18:25

Subject: Re: Getting rid of a stale remote?
Message-ID: <x2uc115fd3c1004061125i695f66bbi9f949ccc1958750@mail.gmail.com>
URL: https://gitlist.dev/e/x2uc115fd3c1004061125i695f66bbi9f949ccc1958750%40mail.gmail.com
In-Reply-To: <w2if3271551004061107rb25b83b9p19a284f19e7d4f87@mail.gmail.com>

```
On Tue, Apr 6, 2010 at 2:07 PM, Ramkumar Ramachandra <artagnon@gmail.com> wrote:
>> 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, 2010-04-06 18:42

Subject: Re: Getting rid of a stale remote?
Message-ID: <20100406184256.GA14281@coredump.intra.peff.net>
URL: https://gitlist.dev/e/20100406184256.GA14281%40coredump.intra.peff.net
In-Reply-To: <x2uc115fd3c1004061125i695f66bbi9f949ccc1958750@mail.gmail.com>

```
On Tue, Apr 06, 2010 at 02:25:07PM -0400, Tim Visher wrote:

> >   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.

>     $ 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, 2010-04-09 02:08

Subject: Re: Getting rid of a stale remote?
Message-ID: <m2nc115fd3c1004081908t15ee034bha4909b56621b4936@mail.gmail.com>
URL: https://gitlist.dev/e/m2nc115fd3c1004081908t15ee034bha4909b56621b4936%40mail.gmail.com
In-Reply-To: <20100406184256.GA14281@coredump.intra.peff.net>

```
On Tue, Apr 6, 2010 at 2:42 PM, Jeff King <peff@peff.net> wrote:
> 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…

> 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

```
