The error is reported as follows
fatal: not in a git directory
Error: Command failed with exit 128: git
Execute repair code
Executing the following codes in sequence will be slower because the downloaded file is larger and is on a foreigner's website:
git -C "/opt/homebrew" remote set-url origin https://github.com/Homebrew/brew
rm -rf "/opt/homebrew/Library/Taps/homebrew/homebrew-cask"
brew tap homebrew/cask
rm -rf "/opt/homebrew/Library/Taps/homebrew/homebrew-core"
brew tap homebrew/core