Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Brew update failed: untracked working tree files would be overwritten by merge

Tags:

homebrew

You need to do the following:

cd $(brew --prefix)
rm Library/Formula/argp-standalone.rb
rm Library/Formula/cocot.rb

And then do the

git fetch origin
git reset --hard origin/master
brew update

Basically, to explain a bit more:

cd $(brew --prefix)

tells cd to change the directory to whatever brew --prefix will output. If you try executing brew --prefix command you should see something in lines of:

brew --prefix
/usr/local

So the command would be in this case an equivalent of cd /usr/local. Newer brew versions have formulae under its installation prefix and Library/Formula/, so that's where you need to look for those outdated/changed files.

Note, that if you changed those formulae yourself for a particular reason (like pinning a version) this action will revert them back to default ones and may produce unwanted effects.

@TedPennings noted in comments that this worked for him, but his sequence was:

  1. chown everything to my_username:admin, ie, sudo chown -R ted:admin $(brew --prefix)
  2. run the two git commands above,git fetch origin and git reset --hard origin/master

cd $(brew --prefix)
git reset --hard HEAD
brew update

This is caused by an old bug in the update code that has long since been fixed. However, the nature of the bug requires that you do the following:

cd $(brew --repository)
git reset --hard FETCH_HEAD

If brew doctor still complains about uncommitted modifications, also run this command:

cd $(brew --repository)    
git clean -fd

$ cd $(brew --prefix)
$ git clean -fd
$ git reset --hard
$ sudo chown -R `whoami` `brew --prefix`
$ brew update

Note: steps 2&3 worked for me since I did step 5 before 4 before I got the error. The brew update before changing the owner of the folder caused the whole problem.