LoginSignup
30
13

brew updateでcouldn't find remote ref refs/heads/masterってエラー。Homebrewも万能じゃないんだね。

Last updated at Posted at 2023-12-12

こんにちは。
フロントエンドエンジニアのみつです。

先日、朝イチでbrew updateがこけてしまって悩み、その解決までの日記です。

目次

起きたこと:cry:

This is happening because the remote branch was renamed or deleted.

brew updateをしたところ、couldn't find remote ref refs/heads/masterというブランチが見つからないエラーに遭遇しました。

remote branchが変更されたり、削除された時に起こるそう。

今回は、Fetchingの際、heroku/brewが見つからなかったそう。

直すには、brew tap --repairをすると良いことも書かれていました。

❯ brew update

fatal: couldn't find remote ref refs/heads/master
Error: Fetching /opt/homebrew/Library/Taps/heroku/homebrew-brew failed!

Installing from the API is now the default behaviour!
You can save space and time by running:
  brew untap homebrew/core
  brew untap homebrew/cask
Updated 1 tap (homebrew/core).
==> Outdated Formulae
gettext                                 openssl@3                               pyenv                                   readline                                ruby-build

You have 5 outdated formulae installed.
You can upgrade them with brew upgrade
or list them with brew outdated.

Error: Some taps failed to update!
The following taps can not read their remote branches:
  heroku/brew
  
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`

tap, untapって何:worried:

これまで、brew updatebrew upgradeで失敗したこともなかったのに加えて、brewはとりあえず簡単インストールのためのツールとしか考えていなかったので・・・

初めてみたコマンドだなぁ、何が起きるコマンドなんだろうなぁと思いながら調べてました。

Tapsは、(Third-Party Repositories)の略らしい。

brew tap means...

brew tap without arguments lists all currently tapped repositories.

brew tapは、現在タップされているすべてのリポジトリを一覧表示するコマンド。

現在の一覧は、下記でした。

❯ brew tap 
heroku/brew
homebrew/cask
homebrew/core
homebrew/services

brew tap --repair means...

brew tap --repair migrates tapped formulae from a symlink-based to directory-based structure. (This should only need to be run once.)

brew tap --repairは、タップした式をシンボリックリンクベースからディレクトリベースに移行するコマンドらしい。

一度だけ実行すればOK、とのこと。

brew untap means...

brew untap user/repo [user/repo user/repo ...] removes the given taps. The repositories are deleted and brew will no longer be aware of their formulae. brew untap can handle multiple removals at once.

与えられたタップを削除するコマンド。

brew untapは一度に複数の削除もOKとのこと。

言われた通り対応してみる:writing_hand:

とりあえず言われた通りに、brew tap --repairをしたら、heroku/brewがしっかりmasterからmainに変更された。

❯ brew tap --repair
remote: Enumerating objects: 24, done.
remote: Counting objects: 100% (24/24), done.
remote: Compressing objects: 100% (17/17), done.
remote: Total 24 (delta 7), reused 22 (delta 7), pack-reused 0
Unpacking objects: 100% (24/24), 12.34 KiB | 485.00 KiB/s, done.
From https://github.com/heroku/homebrew-brew
 * [new branch]      main       -> origin/main
==> heroku/brew: changed default branch name from master to main!

一応、再度brew updateをしてみる。

❯ brew update
Installing from the API is now the default behaviour!
You can save space and time by running:
  brew untap homebrew/core
  brew untap homebrew/cask
Updated 1 tap (heroku/brew).
No changes to formulae or casks.

Warnメッセージ的なものは出ているけど、res/heads/masterが見つからないエラーは解消されているみたい。

後で、untapすると容量と実行時間が節約されるという方も対応しようと思いますが、一旦は、brew upgradeも実行できて大満足。:relaxed:

これでいつも通りのHomebrewが復活です。

まとめ

Homebrewもエラーでて万能じゃないのかぁと一瞬思ったんですが、コマンドでrepairするオプションがあったり、今回は書いていませんがbrew doctorという問題を発見するコマンドもあるので「さっすがぁ」という気持ちでした。

エラーもちゃんと読めば書いてあるな、と改めて。

もっと色んなエラーに巡り合いたいなと思いました。

おわり。

30
13
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
30
13