Error of "error: could not lock config file .git/config: Permission denied" occurs while installing Carthage
Check for the permissions on these files.
ls -l /usr/local/Homebrew/.git/FETCH_HEAD
ls -l /usr/local/Homebrew/Library/Taps/caskroom/homebrew-cask/.git/FETCH_HEAD
ls -l /usr/local/Homebrew/Library/Taps/dart-lang/homebrew-dart/.git/FETCH_HEAD
ls -l /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/.git/FETCH_HEAD
If you don't have the permissions, run
sudo chown -R $(whoami):admin /usr/local/* && sudo chmod -R g+rwx /usr/local/*
In High Sierra and above, Run this command instead:
sudo chown -R $(whoami) $(brew --prefix)/*
You can also see the related github issues here
In High Sierra, run the command:
sudo chown -R $(whoami) $(brew --prefix)/*