First find out what is the current ownership of the installed package of brew (you will need this info in the last step)
ls -al `which brew`
Change the user and group of brew to root and wheel respectively:
sudo chown root:wheel `which brew`
Now execute your brew command as root, for eg. sudo brew link mcrypt. Lastly, revert back the ownership of brew to what you had found out in step 1 above
sudo chown : `chown brew`
brew update failure while executing git checkout
$ cd `brew --prefix`
$ git remote add origin https://github.com/Homebrew/homebrew.git
$ git fetch origin
$ git reset --hard origin/master
$ brew update
Already up-to-date.