23

I am trying to install Homebrew. However, the following error happened.

fatal: couldn't find remote ref refs/heads/master
Error: Fetching /opt/homebrew/Library/Taps/dart-lang/homebrew-dart failed!
Error: Some taps failed to update! The following taps can not read their remote branches:   
       dart-lang/dart
This is happening because the remote branch was renamed or deleted.
Reset taps to point to the correct remote branches by running 'brew tap --repair'
Failed during: /opt/homebrew/bin/brew update --force --quiet

I have tried to run

brew tap --repair

but it turned out that zsh: command not found: brew Does anyone know how to fix it?

user21251016
  • 231
  • 1
  • 3

5 Answers5

46

I had the same issue.

dart-lang seemed to be the culprit.

brew update-reset said that everything was up-to-date apart from:

==> Fetching /usr/local/Homebrew/Library/Taps/dart-lang/homebrew-dart...
fatal: couldn't find remote ref refs/heads/master
error: Not a valid ref: refs/remotes/origin/main

brew tap --repair failed like so:

fatal: couldn't find remote ref refs/heads/master
Error: Failure while executing; `git -C /usr/local/Homebrew/Library/Taps/dart-lang/homebrew-dart fetch origin` exited with 128.

Running brew doctor didn't show up anything pertinent, so some further digging was required.

Heading over to the dart-lang repo showed the very error as an issue & in the thread there, a solution: https://github.com/dart-lang/homebrew-dart/issues/131#issuecomment-1411094620

So here's the code that Nakji wrote there:

cd /usr/local/Homebrew/Library/Taps/dart-lang/homebrew-dart
git branch -m master main
git remote remove origin
git remote add origin https://github.com/dart-lang/homebrew-dart

Follow that up with the specific brew tap --repair dart-lang/dart which can then do its magic.

Brew is now able to update

ugy
  • 609
  • 4
  • 6
24

This worked for me:

brew tap --repair
brew cleanup
brew update-reset

After that I was able to brew update without any issues.

Possible culprit: dart-lang/dart: changed default branch name from master to main!

Mihai-Cristian
  • 420
  • 2
  • 8
2

Try brew update-reset, if it does not work, can you paste brew doctor output?

chenrui
  • 8,910
  • 3
  • 33
  • 43
2

For me, none of the above solutions worked. I was about to delete and reinstall Homebrew. Then I tried removing the dart-lang/dart tap and it worked for me. Just go to the /usr/local/Homebrew/Library/Taps folder and delete dart-lang folder to remove the tap from brew locally.

-2

try

rm -rf /usr/local/bin/brew rm -rf /usr/local/share/doc/homebrew rm -rf /usr/local/share/man/man1/brew.1 rm -rf /usr/local/share/zsh/site-functions/_brew rm -rf /usr/local/etc/bash_completion.d/brew rm -rf /usr/local/Homebrew

then repeat the installation

Fox682
  • 1