114

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

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
andrewpthorp
  • 4,998
  • 8
  • 35
  • 56
  • 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 '11 at 18:23

3 Answers3

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
corysimmons
  • 7,296
  • 4
  • 57
  • 65
  • 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 05 '16 at 03: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 '16 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 '16 at 23:41
  • 2
    You can try to fix it by doing `sudo chown -R yourusername:admin /usr/local/.git` – sschueller Oct 19 '16 at 11:56
  • 5
    FYI: it may also be `cd /usr/local/Homebrew` – Fayaz Jan 27 '17 at 03:35
  • Can't i just `git pull` to get the latest master? or pull a specific tag? why do i need to `brew update`? – denns Mar 13 '17 at 17:20
  • NB currently sudo brew update yields; Error: Cowardly refusing to 'sudo brew update' You can use brew with sudo, but only if the brew executable is owned by root. However, this is both not recommended and completely unsupported so do so at your own risk. – AnneTheAgile Apr 04 '18 at 01:22
  • BE CAREFUL!! Discarding everything in your `/usr/local` directory could really mess up your computer. Make sure you know exactly what you're deleting before you use git to delete files in /usr/local (or anywhere else). I'd recommend following the instructions here, instead: https://docs.brew.sh/Common-Issues – edan Dec 16 '20 at 17:48
28

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

nzoLogic
  • 323
  • 3
  • 12
  • % 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 06 '21 at 08: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` – Niall Mccormack Nov 09 '21 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)"
Peter O'Brien
  • 185
  • 1
  • 7
  • 18
    be careful this script will remove all applications that you've installed via `brew` – nesimtunc Oct 11 '16 at 07:11
  • 4
    Reinstalling brew with this method does not seem to cause installed applications to be removed anymore. – kas Apr 17 '18 at 22:32