Error while trying to update brew package manager

Solution 1:

There was a bug in Homebrew that was fixed just a few days ago. To fix the bug you can run git reset --hard FETCH_HEAD inside your Homebrew installation. Since that won't fix files that are already seen as modified you can also run git checkout Library to replace your checkout with the latest files. (That wipes all edits so take appropriate measures with any you made.)

Solution 2:

The accepted answer is correct but incomplete. If you are getting the error of

error: The following untracked working tree files would be overwritten by merge:

Then go to your terminal and run these commands

cd /usr/local

Then

git reset --hard FETCH_HEAD

Then

git checkout Library

That should get everything in order. Then run

brew update

Solution 3:

Let me add: cd /usr/local/git and then run git reset --hard FETCH_HEAD

Solution 4:

go to your terminal and run these commands

cd /usr/local

sudo git reset --hard FETCH_HEAD

sudo git checkout Library

Solution 5:

For those of you using OS X El Capitan, your problem may be System Integrity Protection.

If /usr/local exists already, run the following in Terminal:

sudo chown -R $(whoami):admin /usr/local

If /usr/local does not exist:

First, try to create /usr/local the normal way:

sudo mkdir /usr/local && sudo chflags norestricted /usr/local && sudo chown -R $(whoami):admin /usr/local

If you see permission issues instead try:

  1. Reboot into Recovery mode (Hold Cmd+R on boot) & access the Terminal.
  2. In that terminal run: csrutil disable
  3. Reboot back into OS X
  4. Open your Terminal application and execute the line from just above
  5. Reboot back into Recovery Mode & access the Terminal again.
  6. In that terminal execute: csrutil enable
  7. Reboot back into OS X & you'll be able to write to /usr/local & install Homebrew.