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

Local tag killer

From
Michael Haggerty <mhagger@alum.mit.edu>
Date
Sep 13, 2013, 02:54 UTC
Message-ID
<52327E62.2040301@alum.mit.edu>
A colleague of mine discovered, the hard way, that
    git fetch --tags --prune $REMOTE

deletes all local tags that are not present on that particular remote. To me this seems a dangerous and poorly-documented interaction of features and arguably a bug.

Granted, it might not be such a good idea to use local tags, as it is all to easy to push them inadvertently and then it is difficult to remove them permanently from a shared upstream repository because other people might have fetched them and in turn inadvertently re-push them.

But the fact that combining two options, each of which seems safe and reasonable for daily use, results in the death of local tags unrelated to the remote is unexpected [1]. Also remember that the "--prune" feature can be turned on permanently via "git config" using "fetch.prune" or "remote.$REMOTE.prune".

Moreover, the documentation is misleading on this point:
> -p::
> --prune::
> 	After fetching, remove any remote-tracking branches which
> 	no longer exist	on the remote.

It is a stretch for references under refs/tags/ to be called "remote-tracking branches", even if they exist as the target of the refspec "refs/tags/*:refs/tags/*" that is implicitly added by the --tags option.

I suggest that --prune should not touch references under refs/tags/ regardless of whether they appear on the right side of explicit or implicit refspecs. If pruning tags is deemed to be essential, then there should be a specific option ("--prune-tags"?) to request it.

When looking into this, I found a test in t5510 that appears to want to verify this very behavior:

Show 10 quoted lines
> test_expect_success 'fetch --prune --tags does not delete the remote-tracking branches' '
> 	cd "$D" &&
> 	git clone . prune-tags &&
> 	cd prune-tags &&
> 	git fetch origin refs/heads/master:refs/tags/sometag &&
> 
> 	git fetch --prune --tags origin &&
> 	git rev-parse origin/master &&
> 	test_must_fail git rev-parse somebranch
> '

However, the last line seems to contain a copy-paste error and should presumably have s/somebranch/sometag/.

Michael

[1] It would be as if "git clean" had two options "--ammonia" and "--bleach" :-)

-- 
Michael Haggerty
mhagger@alum.mit.edu
http://softwareswirl.blogspot.com/
Next: Junio C Hamano
Message 1 of 23 in “Local tag killer”
  1. Michael HaggertySep 13, 2013
  2. Junio C HamanoSep 13, 2013
  3. Junio C HamanoSep 20, 2013
  4. Michael HaggertySep 21, 2013
  5. John SzakmeisterSep 21, 2013
  6. Jeff KingSep 24, 2013
  7. Marc BranchaudSep 24, 2013
  8. Jeff KingSep 25, 2013
  9. Nicolas PitreSep 25, 2013
  10. Michael HaggertySep 28, 2013
  11. Johan HerlandSep 28, 2013
  12. Michael HaggertySep 29, 2013
  13. Johan HerlandSep 29, 2013
  14. Marc BranchaudSep 30, 2013
  15. Nicolas PitreSep 30, 2013
  16. Marc BranchaudSep 30, 2013
  17. Nicolas PitreSep 30, 2013
  18. Marc BranchaudSep 30, 2013
  19. Nicolas PitreSep 30, 2013
  20. Jeff KingSep 30, 2013
  21. Marc BranchaudOct 1, 2013
  22. Nicolas PitreOct 1, 2013
  23. Marc BranchaudOct 1, 2013

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.