How can I remove corrupted remote branches / tags in git?
I don't know how this happened, but somehow our remote repo has branches and tags named as shown when I run the command git ls-remote
:
refs/heads/abc^{}
refs/tags/def^{}
And I cannot delete them in the usual way:
git push origin :refs/heads/abc^{}
fatal: remote part of refspec is not a valid name in :refs/heads/abc^{}
How do I remove these corrupted remote branches?
source to share
This is not a branch, this is the result of a bad branch:
server$ echo echo 2e79bc84c11eda5d73add5a9dfc6bf03c50c432d > refs/heads/oogly
In this case, the selected SHA-1 I was the annotated tag tag. You cannot get "git branch" or "git checkout" to point to a tag, they are always cleared from the commit, but you can get a non-git -aware tool (for example, echo
in this case) to make a split branch.
Then on the client:
client$ git ls-remote
[snip]
d1574b852963482d4b482992ad6343691082412f refs/heads/master
2e79bc84c11eda5d73add5a9dfc6bf03c50c432d refs/heads/oogly
676699a0e0cdfd97521f3524c763222f1c30a094 refs/heads/oogly^{}
[snip]
Removing the actual branch ( oogly
in this case abc
, yours) on the server will cause the "stripped tag" to disappear on the client as well. Note, if you want to keep a tag, you must point the tag to it if it doesn't already exist.
How it was created on the server I don't know.
Note that this is perfectly fine for (annotated) tags: the server provides both the tag and its SHA-1 and SHA-1 of the underlying object it points to. The syntax is described in gitrevisions :
<rev>^{}, e.g. v0.99.8^{}
A suffix ^ followed by an empty brace pair means the object could
be a tag, and dereference the tag recursively until a non-tag
object is found.
source to share