How to repair and/or reinstall Homebrew safely? I am trying to repair Homebrew.

I recently tried to reinstall it but when I typed "brew doctor"

My output was:

shell-init: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
chdir: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
chdir: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
The current working directory doesn't exist, cannot proceed.


I have tried to re-install it by typing this into the command line again:

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


But my output is:

It appears Homebrew is already installed. If your intent is to reinstall you
should do the following before running this installer again:
rm -rf /usr/local/Cellar /usr/local/.git &amp;&amp; brew cleanup


How can I fix my Homebrew install?
This happened to me because I had two tabs open in my console. In Console A I removed the current working directory of Console B. Then, without thinking about it, I ran brew upgrade in Console B. Of course it threw the above error.

Simple solution: just cd to a different directory in Console B and brew upgrade again.

Me and my infinite wisdom.