Search code examples
macoshomebrewpackage-managersmacos-mojave

brew install Freezing


I'm having trouble with brew install <PackageName>

I had macOS BigSur and could use commands like brew easily but in recent downgrade (Mojave) I can't do it anymore

it freeze about 60 second and reply with (If I getting it right) that can't update the main repository


CODE :

Updating Homebrew...
error: Not a valid ref: refs/remotes/origin/master
fatal: ambiguous argument 'refs/remotes/origin/master': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'
fatal: Could not resolve HEAD to a revision
==> Homebrew has enabled anonymous aggregate formula and cask analytics.
Read the analytics documentation (and how to opt-out) here:
  https://docs.brew.sh/Analytics
No analytics have been recorded yet (nor will be during this `brew` run).

==> Homebrew is run entirely by unpaid volunteers. Please consider donating:
  https://github.com/Homebrew/brew#donations
==> Auto-updated Homebrew!
Updated 1 tap (homebrew/cask).
==> New Casks
8x8-work                 disk-expert              guilded                  odbc-manager             ubports-installer
diagnostics              duplicate-file-finder    hush                     pktriot
==> Updated Casks
Updated 352 casks.
==> Deleted Casks
adafruit-arduino                           beautune                                   caramba-switcher
adobe-lens-profile-creator                 blue-jeans-browser-plugin

Warning: No available formula or cask with the name "htop".
==> Searching for similarly named formulae...
Error: No similarly named formulae found.
==> Searching for a previously deleted formula (in the last month)...
Error: No previously deleted formula found.
==> Searching taps on GitHub...
Error: No formulae found in taps.

Solution

  • Homebrew is managed by git repos. From the output, homebrew is detached and homebrew-core repo is missing.

    Let's try following commands to fix the repos.

    # Reset remote repo for Homebrew, the pkg manager itself
    git -C "$(brew --repo)" remote set-url origin https://github.com/Homebrew/brew.git
    
    # Reset origin for homebrew taps
    BREW_TAPS="$(brew tap)"
    for tap in core cask{,-fonts,-drivers,-versions}; do
        if echo "$BREW_TAPS" | grep -qE "^homebrew/${tap}\$"; then
            git -C "$(brew --repo homebrew/${tap})" remote set-url origin https://github.com/Homebrew/homebrew-${tap}.git
        fi
    done
    
    brew update-reset
    

    If it doesn't work, you may have to reinstall Homebrew.