Switch Apple Git to Git, the problem will go away.
Run brew install git
to do it.
Relate link:
https://blog.smittytone.net/2021/05/21/how-to-fix-xcodebuild-macos-terminal-slow-downs/
Another option is to accept the Xcode License
sudo xcodebuild -license accept
You can find this referring to the reference in the linked article.