I don't understand new homebrew update output - homebrew

brew update
Stashing your changes:
M CODEOFCONDUCT.md
M CONTRIBUTING.md
M LICENSE.txt
M README.md
M SUPPORTERS.md
Restored your changes:
M CODEOFCONDUCT.md
M CONTRIBUTING.md
M LICENSE.txt
M README.md
M SUPPORTERS.md
Already up-to-date.
This was done after upgrading to the El Captain OS. Then, when I did a brew update I was asked to 'sudo chown -R$(donfox1):admin /usr/local' then this new mysterious output started happening.
I don't understand what changes are being 'stashed' or if I should do anything about these changes?

If you didn’t do these changes you can fix them by running the following:
cd $(brew --repo) && git fetch && git reset --hard origin/master

Related

Installing previous versions of a formula with brew extract

Due to a problem with the Subversion 1.13 Brew formula I was installing an older revision of the formula:
brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/0c3d786402ad7d9dd5eb6907e3ed3f2525a0472d/Formula/subversion.rb
That gives a warning:
Warning: Calling Installation of subversion from a GitHub commit URL is deprecated! Use 'brew extract subversion' to stable tap on GitHub instead.
The suggestion is the same as this tip.
Now, I'd like to do this properly using brew extract subversion rather than using the deprecated commit URL. I'd like to install Subversion 1.13_5 on some computers, but Subversion 1.14 is the latest formula.
I need to do something like this: brew extract --version 1.13.0_5 subversion <tap>.
The way I understand this I should:
Create an empty repository for my versioned formulas
Add the repository as a tap and initialize it
Extract the versioned formula
Commit and push the formula?
I created an empty repository, then:
$ brew tap rjollos/homebrew-versioned
Cloning into '/usr/local/Homebrew/Library/Taps/rjollos/homebrew-versioned'...
warning: You appear to have cloned an empty repository.
Tapped (16 files, 22.2KB).
$ brew tap-new rjollos/homebrew-versioned
==> Created rjollos/versioned
/usr/local/Homebrew/Library/Taps/rjollos/homebrew-versioned
$ brew extract --version '1.13.0_5' subversion rjollos/homebrew-versioned
==> Searching repository history
Warning: Calling 'devel' blocks in formulae is deprecated! Use 'head' blocks or #-versioned formulae instead.
Please report this issue to the homebrew/core tap (not Homebrew/brew or Homebrew/core), or even better, submit a PR to fix it:
/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/subversion.rb:16
Warning: Calling 'devel' blocks ... (repeats about a dozen times)
Error: subversion: undefined method `sha1' for #<SoftwareSpec:0x00007fceaf144490>
I think I'm doing several things wrong, but mainly I'm unsure why brew extract doesn't work. Also, is there a better way to create a new repository and populate it with the template files for a new tap?
$ brew --version
Homebrew 2.4.4-19-ge09802b
Homebrew/homebrew-core (git revision 5ee797; last commit 2020-07-07)
Homebrew/homebrew-cask (git revision 837ac; last commit 2020-07-08)
Taps can be created locally without actual github repository. Here is general example:
TAP=... # <org>/<repo>, for example "my-org/homebrew-old"
MODULE=... # name of module you want to install, e.g. "hugo"
VERS=... # version of $MODULE you want to install, e.g., "0.80.0"
brew tap-new $TAP
brew extract --version $VERS $MODULE $TAP
brew install $TAP/$MODULE#$VERS
Still not sure this is the best way to create a new tap. I created homebrew-repo on my GitHub, then added the tap, then initialized the tap using tap-new.
$ TAP=rjollos/homebrew-repo
$ TAP_PATH=$(brew --repository)/Library/Taps/$TAP
$ brew tap $TAP
==> Tapping rjollos/repo
Cloning into '/usr/local/Homebrew/Library/Taps/rjollos/homebrew-repo'...
warning: You appear to have cloned an empty repository.
Tapped (16 files, 22.2KB).
$ brew tap-new $TAP
==> Created rjollos/repo
/usr/local/Homebrew/Library/Taps/rjollos/homebrew-repo
$ cd $TAP_PATH
$ git add .
$ git commit -m "Initialized with template files"
[master (root-commit) c7c4bed] Initialized with template files
2 files changed, 29 insertions(+)
create mode 100644 .github/workflows/main.yml
create mode 100644 README.md
$ git remote -v
origin https://github.com/rjollos/homebrew-repo (fetch)
origin https://github.com/rjollos/homebrew-repo (push)
Extract the versioned formula:
$ brew extract --version 1.13.0 subversion $TAP
==> Searching repository history
==> Writing formula for subversion from revision dab5452 to:
/usr/local/Homebrew/Library/Taps/rjollos/homebrew-repo/Formula/subversion#1.13.0.rb
Add the formula:
$ cd $TAP_PATH
$ git add Formula
$ git commit -m "Add Subversion 1.13 formula"
1 file changed, 203 insertions(+)
create mode 100644 Formula/subversion#1.13.0.rb
$ git push
Enumerating objects: 10, done.
Counting objects: 100% (10/10), done.
Delta compression using up to 8 threads
Compressing objects: 100% (7/7), done.
Writing objects: 100% (10/10), 3.99 KiB | 2.00 MiB/s, done.
Total 10 (delta 0), reused 0 (delta 0), pack-reused 0
To https://github.com/rjollos/homebrew-repo
* [new branch] master -> master
I tried brew install <url> approach, seems working well for me?
installation log:
$ brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/0c3d786402ad7d9dd5eb6907e3ed3f2525a0472d/Formula/subversion.rb
Warning: Calling Installation of subversion from a GitHub commit URL is deprecated! Use 'brew extract subversion' to stable tap on GitHub instead.
######################################################################## 100.0%
==> Downloading https://homebrew.bintray.com/bottles/subversion-1.13.0_5.mojave.bottle.tar.gz
Already downloaded: /Users/rchen/Library/Caches/Homebrew/downloads/6c15ae92fb6a09985f1679367588188829b69a4dbc53bb324597fb9fdf588d9e--subversion-1.13.0_5.mojave.bottle.tar.gz
Warning: subversion 1.14.0_2 is available and more recent than version 1.13.0_5.
==> Pouring subversion-1.13.0_5.mojave.bottle.tar.gz
==> Caveats
svntools have been installed to:
/usr/local/opt/subversion/libexec
The perl bindings are located in various subdirectories of:
/usr/local/opt/subversion/lib/perl5
You may need to link the Java bindings into the Java Extensions folder:
sudo mkdir -p /Library/Java/Extensions
sudo ln -s /usr/local/lib/libsvnjavahl-1.dylib /Library/Java/Extensions/libsvnjavahl-1.dylib
Bash completion has been installed to:
/usr/local/etc/bash_completion.d
==> Summary
🍺 /usr/local/Cellar/subversion/1.13.0_5: 234 files, 30.3MB
Removing: /Users/rchen/Library/Caches/Homebrew/subversion--1.13.0_5.mojave.bottle.tar.gz... (8.6MB)
version check
$ svn --version
svn, version 1.13.0 (r1867053)
compiled Apr 17 2020, 12:01:27 on x86_64-apple-darwin18.7.0
Copyright (C) 2019 The Apache Software Foundation.
This software consists of contributions made by many people;
see the NOTICE file for more information.
Subversion is open source software, see http://subversion.apache.org/
The following repository access (RA) modules are available:
* ra_svn : Module for accessing a repository using the svn network protocol.
- with Cyrus SASL authentication
- handles 'svn' scheme
* ra_local : Module for accessing a repository on local disk.
- handles 'file' scheme
* ra_serf : Module for accessing a repository via WebDAV protocol using serf.
- using serf 1.3.9 (compiled with 1.3.9)
- handles 'http' scheme
- handles 'https' scheme
The following authentication credential caches are available:
* Mac OS X Keychain

homebrew/core is a shallow clone in Fish shell

I tried to install something using brew install and this thing pops up
Warning: homebrew/core is shallow clone. To get complete history run:
git -C "$(brew --repo homebrew/core)" fetch --unshallow
and when I copied that thing to make it run, this happens
fish: $(...) is not supported. In fish, please use '(brew)'.
git -C "$(brew --repo homebrew/core)" fetch --unshallow
^
What does it means and how can I fix these things? Is there's a workaround to ignore or fix?
Additional information about my workstation:
MacOS Mojave
Homebrew version 2.0.2
Does run brew doctor and it shows up as no problem
Using Fish shell (of course I do)
Update 1 :
It looks like I am an idiot leaving the $ there.
I did try to fix it with you guys suggestions, and this what happened.
Removing the $ from the command, like so
git -C "(brew --repo homebrew/core)" fetch --unshallow
and this happens
fatal: cannot change to '(brew --repo homebrew/core)': No such file or directory
Update 2 :
Also, #VonC asked me did brew --repo homebrew/core path exists by asking me to run these following line
brew --repo homebrew/core
and it comes up as this
/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core
which indicates that the repository path is still valid and ready to use
As mentioned in fish-shell/issue 1405
In bash, $(...) is equivalent to backticks, except it's supported inside a double-quoted string.
Fish does not use $(...) or backticks, it uses (...) instead
So:
git -C (brew --repo homebrew/core) fetch --unshallow
Issue 159 discusses the support of $() command substitution syntax.
Since 2012.
fatal: cannot change to '(brew --repo homebrew/core)': No such file or directory
Then double-check what brew --repo homebrew/core returns, and if the path exists.
As an alternative, seen here:
git -C $HOMEBREW_CORE fetch --unshallow
Using "" should be supported, as seen in "How to remove the shallow clone warning from HomeBrew", but not advisable, from glenn-jackman's comment.
Simplest explanation for a "shallow clone" is that it's simply a clone of the git repository without the revision history thereby reducing the git repo footprint. You can also specify "depth" to reduce the amount of revision history obtained from a git clone.
In your case, if you need the full history, a fetch --unshallow is needed.
Looks like I did a double oopsies.
Thanks to all comments to me that I am doing an oopsies. I appreciate it a lot.
Instead of typing
git -C "$(brew --repo homebrew/core)" fetch --unshallow
which fish does not really likes $ in that line,
use this instead :
git -C (brew --repo homebrew/core) fetch --unshallow
no $ and ".
AAAAND that's it.
Please comment if this does not help. I still doubt that really resolves this question or not lol

git diff is not showing in meld in ubuntu 14.04?

I installed meld in my ubuntu 14.04 system. by following these commands.
In the following directory path:
anurag#LIBSERV-PC:~$mkdir -p work/crap
anurag#LIBSERV-PC:~$cd work/crap
anurag#LIBSERV-PC:~/work/crap$git clone https://git.gnome.org/browse/meld
anurag#LIBSERV-PC:~/work/crap$cd meld
anurag#LIBSERV-PC:~/work/crap/meld$sudo apt-get install intltool itstool gir1.2-gtksource-3.0 libxml2-utils
anurag#LIBSERV-PC:~/work/crap/meld$sudo python setup.py install
It seems installation is done properly. I am working on my rails project in the following location:
anurag#LIBSERV-PC:~/vikas/template$ git diff lib/common_methods.rb
But in my system git diff is not showing in meld software.
I am seeing difference on the terminal only.
As I mentioned in "How to set Meld as git mergetool", you sill have to declare meld as a difftool
git config --global diff.tool meld
Or use git difftool --tool=meld.

How do you migrate a Homebrew installation to a new location?

I have a Homebrew installation in $HOME/brew, and historically it has worked well. Unfortunately, over time Homebrew has become less and less tolerant of installations outside of /usr/local. Various formulae make hard assumptions about the installation prefix, and do not work properly (i.e., were not tested) with a non-standard prefix. The brew doctor command even goes so far as to warn about this now:
Warning: Your Homebrew is not installed to /usr/local
You can install Homebrew anywhere you want, but some brews may only build
correctly if you install in /usr/local. Sorry!
As such, I would now like to migrate my Homebrew installation over to /usr/local. However, I am loath to simply mv all the files, as I suspect this will cause problems. I could not find any instructions on the Homebrew site or here on migrating an existing installation to a new prefix. Of course, I could uninstall Homebrew and then reinstall it, but I would prefer not to rebuild all my kegs.
Is there any existing script or documented practice for performing such a migration?
Or is this impossible due to hardcoded absolute paths in linked binaries?
The modern way to do this is with homebrew-bundle.
brew tap Homebrew/bundle
brew bundle dump # Creates 'Brewfile' in the current directory
# later ...
brew bundle # Installs packages listed in 'Brewfile'
I just wrote a script to achieve the goal to migrate homebrew packages to a new system, which also applies for your case (named backup-homebrew.sh):
#!/bin/bash
echo '#!/bin/bash'
echo ''
echo 'failed_items=""'
echo 'function install_package() {'
echo 'echo EXECUTING: brew install $1 $2'
echo 'brew install $1 $2'
echo '[ $? -ne 0 ] && $failed_items="$failed_items $1" # package failed to install.'
echo '}'
brew tap | while read tap; do echo "brew tap $tap"; done
brew list --formula | while read item;
do
echo "install_package $item '$(brew info $item | /usr/bin/grep 'Built from source with:' | /usr/bin/sed 's/^[ \t]*Built from source with:/ /g; s/\,/ /g')'"
done
echo '[ ! -z $failed_items ] && echo The following items were failed to install: && echo $failed_items'
You should first run this script on your original system to generate a restore script:
./backup-homebrew.sh >restore-homebrew.sh && chmod +x restore-homebrew.sh
Then, after installing Homebrew on your new system (in your case the same system), simply run restore-homebrew.sh to install all those packages you have on your original system.
The benefits of this script over the one given by #ctrueden is that this script also tries to back up the installation options you used when you installed the packages.
A more detailed description is in my blog.
As suggested by Peter Eisentraut, I indeed ended up migrating my Homebrew installation by reinstalling it. You can script things a bit to retap all your extra taps, and reinstall all your previously installed kegs, without too much manual work:
#!/bin/sh
# save list of kegs for later reinstallation
brew list > kegs.txt
# back up old Homebrew installation
mv $HOME/brew $HOME/old-brew
# install Homebrew into /usr/local
ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go)"
# retap all the taps
# NB: It is not enough to move the tap repos to their new location,
# because Homebrew will not automatically recognize the new formulae.
# There might be a configuration file we could edit, but rather than
# risk an incomplete data structure, let's just retap everything.
for tapDir in $HOME/old-brew/Library/Taps/*
do (
cd $tapDir
tap=$(git remote -v | \
grep '(fetch)' | \
sed 's/.*github.com\///' | \
sed 's/ (fetch)//')
/usr/local/bin/brew tap $tap
) done
# reinstall all the kegs
/usr/local/bin/brew install $(cat kegs.txt)
# much later... ;-)
rm -rf kegs.txt $HOME/old-brew
Of course, customized Homebrew installations will have additional wrinkles. For example, if you have committed changes to any of your Homebrew-related Git repos, you may want to import that work before reinstalling your kegs or blowing away your old installation:
cd /usr/local
for f in $(find . -name '.git')
do (
repoDir=$(dirname $f)
cd $f/..
git remote add old-brew-$f $(dirname $HOME/old-brew/$f/..)
git fetch old-brew-$f
) done
Note that I only tested the second snippet above very lightly, as I personally have not customized my Homebrew in such a way.
Another aspect of Homebrew not addressed by this approach is custom flags using during your original installation. For example, to install wine you need to install various dependencies with the --universal flag, and the script above will not reinstall them with such flags enabled. See #xuhdev's answer for a solution that does so.
Or is this impossible due to hardcoded absolute paths in linked binaries?
Indeed. You'll need to reinstall everything from scratch.

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

Trying to update Homebrew with brew update I got the following error
error: The following untracked working tree files would be overwrittenby merge:
Library/Formula/argp-standalone.rb
Library/Formula/cocot.rb
Please move or remove them before you can merge.
Aborting
Updating e088818..5909e2c
Error: Failed while executing git pull origin refs/heads/master:refs/remotes/origin/master
I found a blog post by someone who experienced a similar problem after having installed Mountain Lion (which I did this week too). He explains how he removed the files referred to in the error message
I removed these files:
$ cd $(brew --prefix)
$ rm cocot.rb
However, removing these files didn't help with the brew update. Instead I had to manually update brew through git:
$ cd $(brew --prefix)
$ git fetch origin
$ git reset --hard origin/master
$ brew update
Already up-to-date.
Assuming those instructions are correct (which I maybe shouldn't assume), I tried to follow these instructions and do
$ cd $(brew --prefix)
$ rm cocot.rb
However, it said 'file doesn't exist' when I tried to rm cocot.rb
One thing I'm not sure about is the cd $(brew --prefix) Are those the exact words I type or do I have to replace prefix with something? the cd was successful, so I'm assuming it was correct -- it moved me into /usr/local, but there was no file to remove. Contents of /usr/local are
Cellar clamXav git mysql var Library doc heroku mysql-5.5.15-osx10.6-x86_64 README.md etc include rvm bin foreman lib share
At any rate, do you know how I can fix the 'brew update'
Update: After removing the files according to favoretti's instructions and trying chown -R <your_username> $(brew --prefix)/.git, I got the following error running brew update
error: The following untracked working tree files would be overwritten by merge:
Library/Aliases/gperftools
Library/Aliases/hashdeep
Library/Aliases/htop
Library/Aliases/nodejs
Library/Aliases/ocio
Library/Aliases/oiio
Library/Aliases/pgrep
Library/Aliases/pkill
Library/Aliases/qt4
Library/Aliases/twolame
Library/Aliases/wxwidgets
Library/Contributions/cmds/brew-aspell-dictionaries
Library/Contributions/cmds/brew-beer.rb
Library/Contributions/cmds/brew-dirty.rb
Library/Contributions/cmds/brew-graph
Library/Contributions/cmds/brew-grep
Library/Contributions/cmds/brew-leaves.rb
Library/Contributions/cmds/brew-linkapps.rb
Library/Contributions/cmds/brew-ls-taps.rb
Library/Contributions/cmds/brew-man
Library/Contributions/cmds/brew-md5-to-sha1
Library/Contributions/cmds/brew-mirror-check.rb
Library/Contributions/cmds/brew-pull.rb
Library/Contributions/cmds/brew-readall.rb
Library/Contributions/cmds/brew-server
Library/Contributions/cmds/brew-services.rb
Library/Contributions/cmds/brew-switch.rb
Library/Contributions/cmds/brew-test-bot.rb
Library/Contributions/cmds/brew-tests.rb
Library/Contributions/cmds/brew-unpack.rb
Library/Contributions/cmds/brew-which.rb
Library/Contributions/cmds/git
Library/Contributions/cmds/svn
Library/ENV/4.3/apr-1-config
Library/ENV/4.3/bsdmake
Library/ENV/4.3/c++
Library/ENV/4.3/c89
Library/ENV/4.3/c99
Library/ENV/4.3/cc
Library/ENV/4.3/clang
Library/ENV/4.3/clang++
Library/ENV/4.3/cpp
Library/ENV/4.3/g++
Library/ENV/4.3/gcc
Library/ENV/4.3/git
Library/ENV/4.3/i686-apple-darwin11-llvm-g++-4.2
Library/ENV/4.3/i686-apple-darwin11-llvm-gcc-4.2
Library/ENV/4.3/ld
Library/ENV/4.3/llvm-g++
Library/ENV/4.3/llvm-g++-4.2
Library/ENV/4.3/llvm-gcc
Library/ENV/4.3/llvm-gcc-4.2
Library/ENV/4.3/make
Library/ENV/4.3/mig
Library/ENV/4.3/sed
Library/ENV/4.3/svn
Library/ENV/4.3/xcrun
Library/ENV/libsuperenv.rb
Library/ENV/pkgconfig/leopard/libcrypto.pc
Library/ENV/pkgconfig/leopard/libcurl.pc
Library/ENV/pkgconfig/mountain_lion/libcurl.pc
Library/ENV/pkgconfig/mountain_lion/libexslt.pc
Library/ENV/pkgconfig/mountain_lion/libxml-2.0.pc
Library/ENV/pkgconfig/mountain_lion/libxslt.pc
Library/Formula/abcl.rb
Library/Formula/abcmidi.rb
Library/Formula/aiccu.rb
Library/Formula/akka.rb
Library/Formula/alac.rb
Library/Formula/alure.rb
Library/Formula/appledoc.rb
Library/Formula/arangodb.rb
Library/Formula/argp-standalone.rb
Library/Formula/argtable.rb
Library/Formula/autopano-sift-c.rb
Library/Formula/avian.rb
Library/Formula/avidemux.rb
Library/Formula/avro-cpp.rb
Library/Formula/aws-cloudsearch.rb
Library/Formula/aws-sns-cli.rb
Library/Formula/backupninja.rb
Library/Formula/bact.rb
Library/Formula/bam.rb
Library/Formula/basex.rb
Library/Formula/berkeley-db4.rb
Library/Formula/bind.rb
Library/Formula/blazeblogger.rb
Library/Formula/bochs.rb
Library/Formula/boost149.rb
Library/Formula/bsdconv.rb
Library/Formula/bsdmake.rb
Library/Formula/buildapp.rb
Library/Formula/bup.rb
Library/Formula/byacc.rb
Library/Formula/cadubi.rb
Library/Formula/camellia.rb
Library/Formula/casperjs.rb
Library/Formula/ccextractor.rb
Library/Formula/cconv.rb
Library/Formula/cdo.rb
Library/Formula/cdpr.rb
Library/Formula/cgvg.rb
Library/Formula/checkstyle.rb
Library/Formula/chordii.rb
Library/Formula/chruby.rb
Library/Formula/cifer.rb
Library/Formula/clhep.rb
Library/Formula/cntlm.rb
Library/Formula/cocot.rb
Library/Formula/cogl.rb
Library/Formula/collada-dom.rb
Library/Formula/crash.rb
Library/Formula/crossroads.rb
Library/Formula/crosstool-ng.rb
Library/Formula/css-crush.rb
Library/Formula/csync.rb
Library/Formula/ctemplate.rb
Library/Formula/curlftpfs.rb
Library/Formula/cutter.rb
Library/Formula/cvsutils.rb
Library/Formula/darkstat.rb
Library/Formula/darner.rb
Library/Formula/dart.rb
Library/Formula/dasm.rb
Library/Formula/debianutils.rb
Library/Formula/dfc.rb
Library/Formula/dgtal.rb
Library/Formula/dhcping.rb
Library/Formula/di.rb
Library/Formula/dmtx-utils.rb
Library/Formula/drip.rb
Library/Formula/dsniff.rb
Library/Fo
Aborting
Updating e088818..c1fbc29
Error: Failed while executing git pull origin refs/heads/master:refs/remotes/origin/master
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:
chown everything to my_username:admin, ie, sudo chown -R ted:admin $(brew --prefix)
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.
I had a similar issue where my brew package library got downloaded as a root user and then I was not able to run brew update as git would complain about not able to merge the file.
Solution was to do :-
sudo chown -R <user> /usr/local/Library
Resetting the brew repository should be the most efficient way if you don't mind to discard potential modifications on formulas you might have been applied:
$ cd `brew --prefix`
$ git fetch origin
$ git reset --hard origin/master
$ brew cleanup --force
$ brew update
I was able to fix this on my machine by adding admin group write (and setgid bit) permission at these paths:
sudo chmod -R g+ws /usr/local /Library/Caches/Homebrew
The s sets the group id on execution so that the write permissions aren't lost the next time a different admin user updates or upgrades Homebrew.
This answer is somewhat incomplete because when I try to do brew cleanup --force there is a permissions issue when Homebrew tries to remove content in /usr/local/Cellar/. (Unfortunately I'm not able to investigate this further at the moment.)
Another option is to just use git stash.
The brew update command performs a git pull, so if there are any changed files (or even file attributes, which happened to me when I changed permissions in the directory recursively) you have to somehow fix the conflicts. Using git stash is one way; it takes any changes and puts them aside so you effectively revert to the last updated repo version. The Homebrew 'location' is by default /usr/local and it installs as a git repository. You can look for a .git folder to see for yourself. I'm writing a homebrew uninstall script to be posted on my GitHub profile soon with more info.
sudo chown -R USER /usr/local/bin
note - for USER use command whom i.e. your username
sudo brew doctor
This approach may be simpler than some. It involves:
fixing a git issue so you can delegate management of changes to it again.
no manual moves of files or directories.
no manual adjustments of file or directory permissions.
Steps (with notes for those who want explanations):
cd $(brew --repository) // see Note 1 below
git remote add brew https://github.com/Homebrew/brew // see Note 2 below
git pull brew master // promising fast-forward report!
brew update // see Note 3 below
Overview:
From what I can tell, the actual cause of this issue is a change in the repo url. It's now brew and was brew.git. (Full up-to-date url: https://github.com/Homebrew/brew)
Note 1: This first command takes you from anywhere in your file structure to the correct directory. The directory structure is different for me than what others show above (Mac OS 10.11.16), but with this command, those differences should not matter.
Note 2: This second command adds the correct remote url to a new alias; I did so just in case this approach didn't accomplish what I wanted and I needed the previous address again. Since the new remote worked, I'll invite someone else to comment on simply changing the url aliased by origin. I'll happily update the answer to reflect what worked for you.
Note 3: This forth command has exactly the desired result: it reports a large number of updates, including the particularly nice report of "==> Migrated HOMEBREW_REPOSITORY to /usr/local/Homebrew!" (emphasis theirs).
This post helped me after updating to El Capitan. In my case, chown wasn't working ("zsh: command not found: chown"), so step 1 was adding this line to my .zshrc:
export PATH="$PATH:/usr/sbin"
I'd already tried several of the more popular answers above, so I'm pretty sure that git status was coming up clean by the time I pasted in the critical command from the blog post:
sudo chown $(whoami):admin /usr/local && sudo chown -R $(whoami):admin /usr/local
This should work.
1. cd `brew --prefix`
2. git fetch origin
3. git reset --hard origin/master
4. sudo brew update

Resources