Homebrew shows git-related errors

Issue

Recently, when I run brew install with any package, before starting installation Homebrew is always showing the following git-related output.

error: Cannot determine remote HEAD
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>...]'
error: Cannot determine remote HEAD
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>...]'

Remark: just to clarify, yes, it is the same message printed twice.
(but perhaps each message is related to a different repository)

I tried to make some auto fixes running brew doctor and brew cleanup but the above output is still showing up.

What does it mean? Perhaps something got altered after installing some packages?

Do you have any suggestion on how to fix this?

Solution

TL;DR: If you just want the solution/workaround, ignore the "How I found the issue" section and the appendix at the end.

How I found the issue

After running the brew command below

brew update -vd --preinstall >brewlog.txt 2>&1

and inspecting the brewlog.txt file, I realized that the two errors show up when Homebrew tries to access two taps I created on my Github.com account in order to "extract" older versions of some packages in order to install those older versions, as this procedure is specifically suggested by Homebrew (see the attached notes at the end).

In particular, during auto-update Homebrew tries to access those two taps, i.e. the corresponding two repositories, and tries to run the following two commands.

git remote set-head origin --auto
git symbolic-ref refs/remotes/origin/HEAD

But since those taps I created on my Github account were stored as empty repositories, therefore there were no commits and there was no HEAD, and therefore git replies with Cannot determine remote HEAD and the rest of the error messages.

How I understood what to do

In order to solve this, or at least to make a workaround, I just added some contents to the repositories. In particular, the brewlog.txt file showed that the above git commands are executed from inside the following kind of path.

/usr/local/Homebrew/Library/Taps/GITHUBACCOUNTNAME/PACKAGENAME

So I navigated to those two folders and I noticed that locally there was actually a folder named Formula containing a file whose name was PACKAGENAME.rb. This contents was stored by Homebrew while installing the old versions, I suppose.

How I solved it

So, what I did in order to “populate” my two Github taps was to just add those contents to the remote taps by running the following commands from each of the two folders.

git add Formula
git commit -m "First commit"
git push

Now there is a HEAD in those two taps and Homebrew is not complaining anymore.

Further notes about installation of older versions

In the past it was possible to install an older version of a Homebrew package just by finding the “right commit” on Github (look here for details) and writing something like this.

brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/8cf29889111b44fd797c01db3cf406b0b14e858c/Formula/PACKAGENAME.rb

Now this does not work anymore, since Homebrew replies with something like this:

Invalid usage: Installation of PACKAGENAME from a GitHub commit URL is unsupported! `brew extract PACKAGENAME` to a stable tap on GitHub instead. (UsageError)

So this is what I did, I created two (private) empty taps on my Github account and I used brew extract to "extract" the older versions to those taps, therefore using those two taps as "pointers" to the older versions.

But this extraction is done just locally by Homebrew, so the repositories where still empty on my Github account, and when doing auto-update and checking those two repositories Github was not managing to determine a remote HEAD. Therefore I solved this as explained above.

Answered By – Kubuntuer82

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published