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'
You'll often need to delete a branch not only locally but also remotely. To do that, you use the following command: git push <remote_name> --delete <branch_name>.
To remove the last commit from git, you can simply run git reset --hard HEAD^ If you are removing multiple commits from the top, you can run git reset --hard HEAD~2 to remove the last two commits. You can increase the number to remove even more commits.
Deleting a branch LOCALLYDelete a branch with git branch -d <branch> . The -d option will delete the branch only if it has already been pushed and merged with the remote branch. Use -D instead if you want to force the branch to be deleted, even if it hasn't been pushed or merged yet. The branch is now deleted locally.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With