47

I tried to update brew:

sudo brew update

But I got this error:

error: Your local changes to the following files would be overwritten by merge:

Listing a lot of files

Error: Failed while executing git pull http://github.com/mxcl/homebrew.git master

Any idea what is going wrong?

3
  • 2
    Homebrew recommends not using sudo, so you should be able to run brew update without it.
    – Clay
    Sep 29, 2011 at 13:33
  • Some OS X El Capitan users will experience this problem for a different reason. See my answer below.
    – Joe Hansen
    Nov 10, 2015 at 22:10
  • do not use sudo for Homebrew
    – pixel 67
    Dec 22, 2016 at 9:23

6 Answers 6

78

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.)

4
  • 3
    I run git reset --hard FETCH_HEAD in /usr/local but I got: fatal: ambiguous argument 'FETCH_HEAD': both revision and filename
    – Chiron
    Aug 7, 2011 at 2:28
  • 2
    The cause for this is that I once ran brew with sudo. That created some files with the wrong permissions (owned by root.) Once I chown'ed the files, then ran that git reset, things were fine. Thanks! Feb 8, 2012 at 13:48
  • 1
    I got the same 'fatal', but I don't know what files to chown, how can I discover it?
    – rafa
    Nov 6, 2013 at 19:56
  • 8
    @rafa sudo chown -R $(whoami) /usr/local
    – pixel 67
    Mar 21, 2014 at 8:39
34

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
15

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

0
11

go to your terminal and run these commands

cd /usr/local

sudo git reset --hard FETCH_HEAD

sudo git checkout Library
11

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.
5

Out of no reason (or at least no one I'd understand) the repository in /usr/local (which is the brew install!) lost its remote repository. So, neither a git reset nor a git pull and for sure no brew update would work.

How do you know that happened? Check /usr/local/.git/config whether there are some lines like the following:

[remote "origin"]
url = http://github.com/mxcl/homebrew.git
fetch = +refs/heads/*:refs/remotes/origin/*

If not do as follows:

cd /usr/local
git remote add origin http://github.com/mxcl/homebrew.git
git pull origin master
1
  • This happened to me too! Thanks @Achim
    – stringy05
    Jul 16, 2013 at 23:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.