Homebrew – Fix ‘Brew Cannot Find Git’ Error

githomebrewterminal

I managed to move brew and php from an M1 silicon to an Intel Mac.

The php is broken due to different processors. And I would resolve that by installing a new php version with brew. This isn't about PHP, but about fixing my homebrew setup so I can return to the main act.

I'm thinking the Brew installation script is broken because it can't find git or can't realize I want to start freshly.

The install script when I run it ends in

Press RETURN/ENTER to continue or any other key to abort:
==> /usr/bin/sudo /usr/sbin/chown -R mattiaswelander:admin /usr/local/Homebrew
Unexpected Git version: ''!
You must install Git before installing Homebrew. See:
  https://docs.brew.sh/Installation

I have git, as git –version reveals:

mattiaswelander@a ~ % git --version
git version 2.39.2 (Apple Git-143)

I even tried downgrading to the git binary suggested by https://git-scm.com/downloads

mattiaswelander@a ~ % git --version
git version 2.15.0

but brew still can't find git, same error about version ''!

Running mattiaswelander@a ~ % which -a git

Reveals that I now have 3 sets of git installed:

/opt/homebrew/bin/git
/usr/local/bin/git
/usr/bin/git

And it seems that homebrew tries to use the version it thinks is installed using homebrew (the /opt/homebrew/bin/git version) but apparently that one doesn't work.

Potentially because it was built for a silicon chipset and it has now been unintentionally moved to an Intel machine (using the mac moving assistant).

How can I remove this from brew?

None of the suggested methods for uninstalling brew (like here https://osxdaily.com/2018/08/12/how-uninstall-homebrew-mac/) work, since they all require git…

———– UPDATE ————-

By removing the /opt/homebrew/bin/git file, homebrew is no longer broken due to the lack of git. It is however broken due to this:

Error: Cannot install on Intel processor in ARM default prefix (/opt/homebrew)!

Is there a way to manually change that prefix to tell it what architecture it should install/self-update for?

The uninstall-scripts as suggested below don't work (because I'm on Ventura?)

Best Answer

I suggest uninstalling homebrew and then reinstalling it and your packages following this guide.

Although this would seem to be more tedious than fixing the PATH to git, a clean uninstall/reinstall is guaranteed to end with a sound build.

You currently have a homebrew installation that was built on a different architecture from where it sits. The issues begins with the PATH order as noted by @Allan and @bmike.