How to delete the git reference `refs/original/refs/heads/master`?
Solution 1
Alexey Ten has the better answer for this because it handles branches, tags, and packed refs. Future visitors should try that solution before this one.
If it's a tag, 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.
Solution 2
This command should work
git update-ref -d refs/original/refs/heads/master
Solution 3
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.
Xiè Jìléi
+--[ RSA 1024]----+ | | | | | . . o | | . o o o o | | S . o + .| | . . + + o | | . . . . . o + | | = o . o . | | =.. ooE| +-----------------+ 1024 aa:0c:4f:fb:15:5c:7e:4c:e7:f1:ca:61:8a:fd:0f:fe X.J. Lenik (RSA)
Updated on September 18, 2022Comments
-
Xiè Jìléi over 1 year
What's this in the yellow round box?
I've tried
git branch -D
,git tag -d
but none succeeded. So how to delete it?-
Jonathon Reinhart over 8 yearsPlease consider changing the accepted answer to Alexey Ten's answer which is highly-upvoted, and correct (
git update-ref -d
).
-
-
Xiè Jìléi almost 13 yearsIt's not a tag, however, I've found it as
.git/refs/original/refs/heads/master
. -
its4zahoor over 11 years+1: You should always use
git update-ref -d
instead of justrm
ing the ref - bad things can happen otherwise. -
40XUserNotFound over 10 years"Pushing nothing" to delete the reference locally is very clever.
-
Daniel Alder over 8 yearsThis should be the accepted answer
-
wahnfrieden over 8 years@CallumRogers why?
-
Alexey Ten about 8 years@wahnfrieden because git could use packed refs and there will be no corresponding file in
refs
directory -
C4F over 5 yearsMade my day. I had a reference to a remote tag that the remote no longer existed. This is the only command that worked.
-
wchargin over 5 yearsUse
git update-ref
rather than manually mutating Git's internals. See Alexey's answer. -
0xC0000022L over 3 yearsOh, it's that one out of the grab bag of nearly 200 Git subcommands with many more (inconsistent) command line switches 😁 ...
-
Admin almost 2 yearsI was bashing my head against "error: dst refspec main matches more than one" because I had a
ref/head/main
and aref/heads/main
due to a typo. Your answer saved my head.