I have tried to install Homebrew on macOS Monterey by following the instructions at https://brew.sh/.
But it resulted in:
error: Not a valid ref: refs/remotes/origin/master
Error: Fetching /opt/homebrew/Library/Taps/homebrew/homebrew-core failed!
fatal: invalid upstream 'origin/master'
Failed during: /opt/homebrew/bin/brew update --force --quiet

I encountered this error on my brand new Macbook Pro with the M2 processor. What worked for me was removing the contents of the homebrew directory
rm -rf /opt/homebrew
Then running the uninstall script (its the same as the intall script on the homebrew except change the last part from install to uninstall. Assuming the link has not changed on the homebrew website I ran these two commands and it installed successfully.
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/uninstall.sh)"
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
You can run brew -v or brew doctor to check if your install is good.
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