[macOS General] Homebrew で fatal: couldn’t find remote ref refs/heads/master エラーが発生した場合の解決方法

ブランチの名前が変わった事が原因。
memo.

症状

brew update したら、こんなエラーが発生。

% brew update
fatal: couldn't find remote ref refs/heads/master
Error: Fetching /usr/local/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`

ブランチ名が master から main に変わったことで発生するやつ。

対応

とりあえずローカルを書き換えておく。

% 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

brew tap --repair も念のため実行しておく。

% brew tap --repair dart-lang/dart
remote: Enumerating objects: 567, done.
remote: Counting objects: 100% (567/567), done.
remote: Compressing objects: 100% (178/178), done.
remote: Total 550 (delta 427), reused 492 (delta 371), pack-reused 0
Receiving objects: 100% (550/550), 97.39 KiB | 5.41 MiB/s, done.
Resolving deltas: 100% (427/427), completed with 11 local objects.
From https://github.com/dart-lang/homebrew-dart
 * [new branch]      deps                -> origin/deps
 * [new branch]      main                -> origin/main
 * [new branch]      pub-dependabot      -> origin/pub-dependabot
 * [new branch]      sortie-pull-request -> origin/sortie-pull-request
 * [new branch]      update-homebrew     -> origin/update-homebrew
==> dart-lang/dart: changed default branch name from master to main!

これで brew update が通るようになる。

参考

dart - fatal: couldn’t find remote ref refs/heads/master - Stack Overflow