113

When I ran:

brew update

I got a message saying it initialized an empty repository in /usr/local/.git/, then I got this error:

Screenshot

1
  • 4
    If you are just looking for a quick way to fix this issue ASAP, you can do the following command in your shell while in the root of your Homebrew directory (usually /usr/local/) with Git installed on your system: git init; git fetch https://github.com/mxcl/homebrew.git master; git reset --hard FETCH_HEAD; brew update.
    – jmlane
    May 19, 2011 at 18:23

3 Answers 3

68
  • cd /usr/local
  • git status
  • Discard all the changes (unless you actually want to try to commit to Homebrew - you probably don't)
  • git status til it's clean
  • brew update
8
  • 11
    Instead of discarding changes, it may be better to git stash changes. Then after you're done updating, run git stash pop to restore your custom modifications
    – kevnk
    Feb 5, 2016 at 3:16
  • 1
    I did exactly this, stashed all changes in /usr/local ... but running 'brew update' continues to give me permission errors on certain git files. I made the mistake of doing 'sudo brew update' which now seems to have bricked my installation and every brew command now gives ruby errors
    – PandaWood
    Feb 19, 2016 at 10:40
  • i did sudo brew update too and now getting that ruby errors like you said .. what do i do now? :'(
    – Laurence
    Mar 24, 2016 at 23:41
  • 2
    You can try to fix it by doing sudo chown -R yourusername:admin /usr/local/.git
    – sschueller
    Oct 19, 2016 at 11:56
  • 5
    FYI: it may also be cd /usr/local/Homebrew
    – Fayaz
    Jan 27, 2017 at 3:35
27

As of 2021 you can simply use brew update which updates homebrew itself.

2
  • % brew update Error: homebrew-core is a shallow clone. homebrew-cask is a shallow clone. To brew update, first run: git -C /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core fetch --unshallow git -C /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask fetch --unshallow These commands may take a few minutes to run due to the large size of the repositories. This restriction has been made on GitHub's request because updating shallow clones is an extremely expensive operation due to the tree layout and traffic of Homebrew/homebrew-core and Home.....
    – 林东吴
    Nov 6, 2021 at 8:58
  • Not always. The default installation needs to be adapted before an upgrade command can work. e.g. I needed to run these two commands git -C /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core fetch --unshallow git -C /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask fetch --unshallow Before running brew update Nov 9, 2021 at 11:09
9

Alternatively you could update brew by installing it again. (Think I did this as El Capitan changed something)

Note: this is a heavy handed approach that will remove all applications installed via brew!

Try to install brew a fresh and it will tell how to uninstall.

At original time of writing to uninstall:

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall)"

Edit: As of 2020 to uninstall:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall.sh)"
2
  • 18
    be careful this script will remove all applications that you've installed via brew
    – nesimtunc
    Oct 11, 2016 at 7:11
  • 4
    Reinstalling brew with this method does not seem to cause installed applications to be removed anymore.
    – kas
    Apr 17, 2018 at 22:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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