gitbitbucket

Get rid of a spurious `HEAD` git tag that is freaking us off


In October 2024, a mysterious git tag named HEAD suddenly appeared in our project.

This caused plethora of errors such as Warning: ambiguous refname HEAD preventing us from even changing branch.

To be frankly honest, I don't get the exact cause, nor creator (which, frankly, doesn't matter so much).

This tag points to a commit dated 2 October 2024 in my repository, and it was a pull request merged via BitBucket. No special change done then.

As for the HEAD naming, I must say I have a suspect that it could be linked to the maven-release-plugin for the reasons I am going to explain.

I can see that the pom.xml, when you use the aforementioned plugin, keeps on modifying <scm><tag>HEAD</tag></scm>, and in that moment in the history we introduced the plugin from short time (2 weeks according to history).

What freaks me off is that this tag cannot be eradicated. When I asked, multiple times, colleagues to freeze everything and delete the tag from their own repo, so they won't be able to push it again, it reappeared after one or two days.

I don't know, but I don't think also Jenkins may be the culprit as it can download a repository but has no permission to push (otherwise maven-release-plugin would work in the pipeline, instead we do it locally to create the tags).

The HEAD tag pointing always to the same point in time makes me think it's not related to the plugin.

Given that we use BitBucket, how can we completely eradicate such a spurious tag and prevent anybody from pushing it in the future, once for good?


Solution

  • You can push a tag named HEAD/guard:

    git tag HEAD/guard main
    git push origin --tag HEAD/guard
    

    Now that this tag is in place, it will be impossible to create a tag named HEAD:

    fatal: cannot lock ref 'refs/tags/HEAD': 'refs/tags/HEAD/guard' exists; cannot create 'refs/tags/HEAD'
    

    Sure, you have now a strangely named tag, but at least it doesn't interfer with the usual HEAD.

    In addition, now that all attempts to create the tag will fail, you should be able to find the wrong-doer.