35

What's this in the yellow round box?

screenshot

I've tried git branch -D, git tag -d but none succeeded. So how to delete it?

11

It looks like a tag, so the following command ought to work:

git tag -d refs/original/refs/heads/master

But, since you've said it doesn't, you can just delete the file out of the .git directory. From the repository root, a command like this will get it:

rm .git/refs/tags/refs/original/refs/heads/master

The path may be slightly different if the git-tag command failed, so you may want to cd .git/refs and find the offending head by trial-and-error. Deleting the file will remove the reference from your local repository.

  • 2
    It's not a tag, however, I've found it as .git/refs/original/refs/heads/master. – Xiè Jìléi May 14 '11 at 6:45
  • 1
    Use git update-ref rather than manually mutating Git's internals. See Alexey's answer. – wchargin Oct 27 '18 at 1:00
99

This command should work

git update-ref -d refs/original/refs/heads/master
  • This worked for me with the same problem. Note that the reference was stored in a file called .git/packed-refs. If you open that up you can see the line with the SHA and the string "refs/original/refs/heads/master". You could probably delete that line, but I'd use this command to be safe. – Matt N Aug 10 '12 at 13:07
  • 14
    +1: You should always use git update-ref -d instead of just rming the ref - bad things can happen otherwise. – Callum Rogers Sep 6 '12 at 23:00
  • 3
    This should be the accepted answer – Daniel Alder Sep 3 '15 at 22:29
  • 1
    @CallumRogers why? – wahnfrieden Dec 7 '15 at 21:19
  • 6
    @wahnfrieden because git could use packed refs and there will be no corresponding file in refs directory – Alexey Ten Feb 4 '16 at 8:15
17

This is a ref. Normally created by git filter-branch - it is a pointer to where your branch was before you ran git filter-branch.

And to delete any ref, you can always push nothing to it in the local repository:

git push . :refs/original/refs/heads/master

The other answers also covered pretty well other ways of deleting.

  • 1
    "Pushing nothing" to delete the reference locally is very clever. – 40XUserNotFound Aug 3 '13 at 13:48
  • Made my day. I had a reference to a remote tag that the remote no longer existed. This is the only command that worked. – RW4 Oct 4 '18 at 18:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.