How do I delete a local git branch when it can't look up commit object in 'refs/heads'?

branch, git

Solution

Those error messages sound worrying to me. Your repository might be corrupt. Git should not garbage collect commits that branches are pointing to. You might want to try `git fsck`, as torek suggests, to verify your repository.

However, you could delete the file representing the branch from your git repository:

rm .git/refs/heads/TestBranch123

You should also clean up any references to the branch from your git config files.

Problem

Lately every git pull I do gives me an error message like: error: refs/heads/TestBranch123 does not point to a valid object! These are old branches and I don't care, so I'd just like to delete them so I don't see the error anymore. When I try to delete the branch I can't for a similar error. git branch -D TestBranch123 error: Couldn't look up commit object for 'refs/heads/TestBranch123'

Original source