Johnny Dew Johnny Dew - 1 year ago 85
Git Question

git branch -d <branchname> throws error: branch <branchname> not found

When I type

git branch
i get

* master

but when I try to remove the branch,
git branch -d localbranch
i get a not found error:
error: branch 'localbranch' not found.

I also tried to force the delete with
git branch -D localbranch
but it's giving me the same error.

The branch was corrupted and I did the following procedure, Git repository corrupt (incorrect header check; loose object is corrupt), to remove the corrupted files but now I can't delete the branch.

Answer Source

Branches are stored as files containing the SHA they point to. Try deleting the file for this branch, named localbranch, from the .git/refs/head/ directory within your project:

rm .git/refs/heads/localbranch
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download