brew 提示fatal: not in a git directory

brew install cocoapods 报错

Downloading https://mirrors.aliyun.com/homebrew/homebrew-bottles/cocoapods-1
Already downloaded: /Users/lipengfei/Library/Caches/Homebrew/downloads/f13a33d2b46eb6f5a4cf83859f21e10cbd0757aae8b60afa388dbd5b32465cac--cocoapods-1.11.3.monterey.bottle.tar.gz
fatal: not in a git directory
Error: Command failed with exit 128: git

执行命令

brew -v

发现

Homebrew 3.5.5-6-gf96b9ef
fatal: unsafe repository ('/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core' is owned by someone else)
To add an exception for this directory, call:

    git config --global --add safe.directory /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core
Homebrew/homebrew-core (no Git repository)
fatal: unsafe repository ('/usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask' is owned by someone else)
To add an exception for this directory, call:

    git config --global --add safe.directory /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask
Homebrew/homebrew-cask (no Git repository)

homebrew-core和homebrew-cask目录 被git认为不是一个安全的目录,需要两行命令添加

git config --global --add safe.directory /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core
git config --global --add safe.directory /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask

然后再安装需要的东西,就可以了

你可能感兴趣的:(brew 提示fatal: not in a git directory)