git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Simple git push --tags deleted all branches

From
Mateusz Loskot <mateusz@loskot.net>
Date
Dec 4, 2018, 19:00 UTC
Message-ID
<CABUeae9w4kfrPp3ZkdYpBb3o5cRqdxhvMixUAjVLQzS+2LYF=w@mail.gmail.com>
In-Reply-To
<87va4fyjtv.fsf@evledraar.gmail.com>
On Thu, 29 Nov 2018 at 16:39, Ævar Arnfjörð Bjarmason <avarab@gmail.com> wrote:
Show 79 quoted lines
> On Thu, Nov 29 2018, Mateusz Loskot wrote:
> > On Thu, 29 Nov 2018 at 16:03, Ævar Arnfjörð Bjarmason <avarab@gmail.com> wrote:
> >> On Wed, Nov 28 2018, Mateusz Loskot wrote:
> >> >
> >> > (using git version 2.19.2.windows.1)
> >> >
> >> > I've just encountered one of those WTH moments.
> >> >
> >> > I have a bare repository
> >> >
> >> > core.git (BARE:master) $ git branch
> >> >   1.0
> >> >   2.0
> >> > * master
> >> >
> >> > core.git (BARE:master) $ git tag
> >> > 1.0.1651
> >> > 1.0.766
> >> > 2.0.1103
> >> > 2.0.1200
> >> >
> >> > I published the repo using: git push --all --follow-tags
> >> >
> >> > This succeeded, but there seem to be no tags pushed, just branches.
> >> > So, I followed with
> >> >
> >> > core.git (BARE:master) $ git push --tags
> >> > To XXX
> >> >  - [deleted]               1.0
> >> >  - [deleted]               2.0
> >> >  ! [remote rejected]       master (refusing to delete the current
> >> > branch: refs/heads/master)
> >> > error: failed to push some refs to 'XXX'
> >> >
> >> > And, I've found out that all branches and tags have been
> >> > wiped in both, local repo and remote :)
> >> >
> >> > I restored the repo and tried out
> >> >
> >> > git push origin 1.0
> >> > git push origin --tags
> >> >
> >> > and this time both succeeded, without wiping out any refs.
> >> >
> >> > Could anyone help me to understand why remote-less
> >> >
> >> > git push --tags
> >> >
> >> > is/was so dangerous and unforgiving?!
> >>
> >> Since nobody's replied yet, I can't see what's going on here from the
> >> info you've provided. My guess is that you have something "mirror" set
> >> on the remote.
> >
> > Thank you for responding.
> >
> > The git push --tags hugely surprised me, and here is genuine screenshot
> > https://twitter.com/mloskot/status/1068072285846859776
> >
> >> It seems you can't share the repo or its URL, but could you share the
> >> scrubbed output of 'git config -l --show-origin' when run inside this
> >> repository?
> >
> > Here is complete output. I have not stripped the basics like aliases,
> > just in case.
>
> Right, it's because you used --mirror, the important bit:
>
> > file:config     remote.origin.url=https://xxx.com/core-external-metadata.git
> > file:config     remote.origin.fetch=+refs/*:refs/*
> > file:config     remote.origin.mirror=true
> > file:config
>
> I.e. you have cloned with the --mirror flag, this is what it's supposed
> to do: https://git-scm.com/docs/git-clone#git-clone---mirror
> https://git-scm.com/docs/git-fetch#git-fetch---prune
>
> I.e. you push and git tries to mirror the refs you have locally to the
> remote, including pruning stuff in the remote.

Thank you very much for diagnosing my issue. I was not aware about how --mirror affects the workflow. It all makes perfect sense now.

Best regards,
-- 
Mateusz Loskot, http://mateusz.loskot.net
Previous: Ævar Arnfjörð Bjarmason
Message 6 of 6 in “Simple git push --tags deleted all branches”
  1. Mateusz LoskotNov 28, 2018
  2. Mateusz LoskotNov 28, 2018
  3. Ævar Arnfjörð BjarmasonNov 29, 2018
  4. Mateusz LoskotNov 29, 2018
  5. Ævar Arnfjörð BjarmasonNov 29, 2018
  6. Mateusz LoskotDec 4, 2018

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.