# Git push tries to delete branch twice and fails

4 messages from 2025-06-06 to 2025-06-06. Participants: Ondra Medek, Kristoffer Haugsbakk.
Thread: https://gitlist.dev/t/63593

## Ondra Medek, 2025-06-06 11:20

Subject: Git push tries to delete branch twice and fails
Message-ID: <CAJsoDaFKRz8om1d4YPtaqdyuBuPAiC-xHDuvmYW=VQWEzzXAtg@mail.gmail.com>
URL: https://gitlist.dev/e/CAJsoDaFKRz8om1d4YPtaqdyuBuPAiC-xHDuvmYW%3DVQWEzzXAtg%40mail.gmail.com

```
I have a git 2.49.0 (Windows) and one local working tree is kind of
broken, when I try:

$ git push origin branch1
Total 0 (delta 0), reused 0 (delta 0), pack-reused 0 (from 0)
To file:///c:/...
 * [new branch]            branch1 -> branch1
Everything up-to-date

$ git push origin :branch1
To file:///c:/...
 - [deleted]               branch1
error: unable to delete 'branch1': remote ref does not exist
error: failed to push some refs to 'file:///c:/...'

So, the same `git push` command first deletes the branch and then
fails because it does not exist. It worked well until something
happened and since that time it's broken. I've tried `git gc
--aggressive --prune`, but it didn't help.

When I do `git clone` of the same repository to another local working
tree, then it's OK - the branch is deleted without the error.

Is this a Git bug? Is it possible to fix the local working tree except
for a new git clone?

Note: I am developing an app which uses (creates and deletes) custom
refs often. So, I've hit this bug when trying to delete a custom ref.
I have cleared all custom refs and tried that with Git branches.

Cheers
Andy

```

## Kristoffer Haugsbakk, 2025-06-06 11:41

Subject: Re: Git push tries to delete branch twice and fails
Message-ID: <ad141d46-3170-47d0-860d-46e7b92f878d@app.fastmail.com>
URL: https://gitlist.dev/e/ad141d46-3170-47d0-860d-46e7b92f878d%40app.fastmail.com
In-Reply-To: <CAJsoDaFKRz8om1d4YPtaqdyuBuPAiC-xHDuvmYW=VQWEzzXAtg@mail.gmail.com>

```
On Fri, Jun 6, 2025, at 13:20, Ondra Medek wrote:
> I have a git 2.49.0 (Windows) and one local working tree is kind of
> broken, when I try:
>
> $ git push origin branch1
> Total 0 (delta 0), reused 0 (delta 0), pack-reused 0 (from 0)
> To file:///c:/...
>  * [new branch]            branch1 -> branch1
> Everything up-to-date
>
> $ git push origin :branch1
> To file:///c:/...
>  - [deleted]               branch1
> error: unable to delete 'branch1': remote ref does not exist
> error: failed to push some refs to 'file:///c:/...'

I was note able to reproduce on Git 2.49.0 on Linux.  Both through a
HTTPS remote as well as a local (filesystem) remote.

ˋˋˋ
$ ./git diagnose
Collecting diagnostic info

git version 2.49.0
cpu: x86_64
built from commit: 683c54c999c301c2cd6f715c411407c413b1d84e
sizeof-long: 8
sizeof-size_t: 8
shell-path: /bin/sh
libcurl: 7.81.0
OpenSSL: OpenSSL 3.0.2 15 Mar 2022
zlib: 1.2.11
Repository root: <path>
Available space on '<path>': 202.28 GiB (mount flags 0x1000)
ˋˋˋ

> So, the same `git push` command first deletes the branch and then
> fails because it does not exist. It worked well until something
> happened and since that time it's broken. I've tried `git gc
> --aggressive --prune`, but it didn't help.
>
> When I do `git clone` of the same repository to another local working
> tree, then it's OK - the branch is deleted without the error.
>
> Is this a Git bug? Is it possible to fix the local working tree except
> for a new git clone?
>
> Note: I am developing an app which uses (creates and deletes) custom
> refs often. So, I've hit this bug when trying to delete a custom ref.
> I have cleared all custom refs and tried that with Git branches.
>
> Cheers
> Andy

```

## Ondra Medek, 2025-06-06 11:50

Subject: Re: Git push tries to delete branch twice and fails
Message-ID: <CAJsoDaGjF=2ZGwGdnx+M-1MdtfDWS2uE8+EAZMuu73cXjhWb7Q@mail.gmail.com>
URL: https://gitlist.dev/e/CAJsoDaGjF%3D2ZGwGdnx%2BM-1MdtfDWS2uE8%2BEAZMuu73cXjhWb7Q%40mail.gmail.com
In-Reply-To: <ad141d46-3170-47d0-860d-46e7b92f878d@app.fastmail.com>

```
Yes, I have witten it's just in one local working tree. When I do `git
clone` of the same repository then it's OK. So I do not know how to
simulate it.

Therefore, the workaround is simple - I may just delete the local dir
and clone the repo again. But I would like just to know what happened
and if it's possible to fix it without cloning if the same issue hit
some of our customers.
---
Andy

On Fri, 6 Jun 2025 at 13:43, Kristoffer Haugsbakk
<kristofferhaugsbakk@fastmail.com> wrote:
>
> On Fri, Jun 6, 2025, at 13:20, Ondra Medek wrote:
> > I have a git 2.49.0 (Windows) and one local working tree is kind of
> > broken, when I try:
> >
> > $ git push origin branch1
> > Total 0 (delta 0), reused 0 (delta 0), pack-reused 0 (from 0)
> > To file:///c:/...
> >  * [new branch]            branch1 -> branch1
> > Everything up-to-date
> >
> > $ git push origin :branch1
> > To file:///c:/...
> >  - [deleted]               branch1
> > error: unable to delete 'branch1': remote ref does not exist
> > error: failed to push some refs to 'file:///c:/...'
>
> I was note able to reproduce on Git 2.49.0 on Linux.  Both through a
> HTTPS remote as well as a local (filesystem) remote.
>
> ˋˋˋ
> $ ./git diagnose
> Collecting diagnostic info
>
> git version 2.49.0
> cpu: x86_64
> built from commit: 683c54c999c301c2cd6f715c411407c413b1d84e
> sizeof-long: 8
> sizeof-size_t: 8
> shell-path: /bin/sh
> libcurl: 7.81.0
> OpenSSL: OpenSSL 3.0.2 15 Mar 2022
> zlib: 1.2.11
> Repository root: <path>
> Available space on '<path>': 202.28 GiB (mount flags 0x1000)
> ˋˋˋ
>
> > So, the same `git push` command first deletes the branch and then
> > fails because it does not exist. It worked well until something
> > happened and since that time it's broken. I've tried `git gc
> > --aggressive --prune`, but it didn't help.
> >
> > When I do `git clone` of the same repository to another local working
> > tree, then it's OK - the branch is deleted without the error.
> >
> > Is this a Git bug? Is it possible to fix the local working tree except
> > for a new git clone?
> >
> > Note: I am developing an app which uses (creates and deletes) custom
> > refs often. So, I've hit this bug when trying to delete a custom ref.
> > I have cleared all custom refs and tried that with Git branches.
> >
> > Cheers
> > Andy

```

## Ondra Medek, 2025-06-06 11:57

Subject: Re: Git push tries to delete branch twice and fails
Message-ID: <CAJsoDaHQnwJTnWDT3eeTsH-nC9Tbt019T4W0pocqBSH80_FYqg@mail.gmail.com>
URL: https://gitlist.dev/e/CAJsoDaHQnwJTnWDT3eeTsH-nC9Tbt019T4W0pocqBSH80_FYqg%40mail.gmail.com
In-Reply-To: <CAJsoDaGjF=2ZGwGdnx+M-1MdtfDWS2uE8+EAZMuu73cXjhWb7Q@mail.gmail.com>

```
Ah, got it, I have in .git/config the same path twice (I did it
unintentionally by manual edit):

[remote "origin"]
    url = file:///c:/...
    url = file:///c:/...
    fetch = +refs/heads/*:refs/remotes/origin/*

Sorry for bothering you
Andy

On Fri, 6 Jun 2025 at 13:50, Ondra Medek <xmedeko@gmail.com> wrote:
>
> Yes, I have witten it's just in one local working tree. When I do `git
> clone` of the same repository then it's OK. So I do not know how to
> simulate it.
>
> Therefore, the workaround is simple - I may just delete the local dir
> and clone the repo again. But I would like just to know what happened
> and if it's possible to fix it without cloning if the same issue hit
> some of our customers.
> ---
> Andy
>
> On Fri, 6 Jun 2025 at 13:43, Kristoffer Haugsbakk
> <kristofferhaugsbakk@fastmail.com> wrote:
> >
> > On Fri, Jun 6, 2025, at 13:20, Ondra Medek wrote:
> > > I have a git 2.49.0 (Windows) and one local working tree is kind of
> > > broken, when I try:
> > >
> > > $ git push origin branch1
> > > Total 0 (delta 0), reused 0 (delta 0), pack-reused 0 (from 0)
> > > To file:///c:/...
> > >  * [new branch]            branch1 -> branch1
> > > Everything up-to-date
> > >
> > > $ git push origin :branch1
> > > To file:///c:/...
> > >  - [deleted]               branch1
> > > error: unable to delete 'branch1': remote ref does not exist
> > > error: failed to push some refs to 'file:///c:/...'
> >
> > I was note able to reproduce on Git 2.49.0 on Linux.  Both through a
> > HTTPS remote as well as a local (filesystem) remote.
> >
> > ˋˋˋ
> > $ ./git diagnose
> > Collecting diagnostic info
> >
> > git version 2.49.0
> > cpu: x86_64
> > built from commit: 683c54c999c301c2cd6f715c411407c413b1d84e
> > sizeof-long: 8
> > sizeof-size_t: 8
> > shell-path: /bin/sh
> > libcurl: 7.81.0
> > OpenSSL: OpenSSL 3.0.2 15 Mar 2022
> > zlib: 1.2.11
> > Repository root: <path>
> > Available space on '<path>': 202.28 GiB (mount flags 0x1000)
> > ˋˋˋ
> >
> > > So, the same `git push` command first deletes the branch and then
> > > fails because it does not exist. It worked well until something
> > > happened and since that time it's broken. I've tried `git gc
> > > --aggressive --prune`, but it didn't help.
> > >
> > > When I do `git clone` of the same repository to another local working
> > > tree, then it's OK - the branch is deleted without the error.
> > >
> > > Is this a Git bug? Is it possible to fix the local working tree except
> > > for a new git clone?
> > >
> > > Note: I am developing an app which uses (creates and deletes) custom
> > > refs often. So, I've hit this bug when trying to delete a custom ref.
> > > I have cleared all custom refs and tried that with Git branches.
> > >
> > > Cheers
> > > Andy

```
