2023-10-25 I found a better way:

mv -v .git .git_old &&            # Remove old Git files
git init &&                       # Initialise new repository
git remote add origin "${url}" && # Link to old repository
git fetch &&                      # Get old history
# Note that some repositories use 'master' in place of 'main'. Change the following line if your remote uses 'master'.
git reset origin/main --mixed     # Force update to old history.

Source: https://stackoverflow.com/questions/18678853/how-can-i-fix-a-corrupted-git-repository

2023-08-21 I ran into this with my Obsidian backup and was able to solve this by using the steps in this article: https://zelig880.com/how-to-fix-git-error-bad-object-head