How to fix homebrew error: "invalid active developer path" after upgrade to OS X El Capitan? I get this error when I run brew update:

$ brew update
xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun
xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun
Error: Failure while executing: git checkout -q master


How to fix this issue?
Run the following commands to fix the above error

sudo xcode-select --install
sudo xcode-select -switch /


I found the answer on https://github.com/Homebrew/homebrew/issues/23500

I also had to do this:

sudo chown -R $(whoami):admin /usr/local


Because of some permission issues. However, do this only if you have to.