I had this same problem, but none of the solutions above worked for me.
tl;dr; the solution is to run
sudo cp -R /Library/Developer/CommandLineTools/SDKs/MacOSX12* /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/
which copies the older "MacOSX12" SDK into the Xcode 14 folders and seems to make everyone happy.
Why this is happening
The error I was seeing relating to the
git binary was:
2022-11-14 16:33:18.828 xcodebuild[20025:1284001] Writing error result bundle to /var/folders/mc/tm26v4sd0pv1hncprqdff72h0000gn/T/ResultBundle_2022-14-11_16-33-0018.xcresult
xcodebuild: error: SDK "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.3.sdk" cannot be located.
git: error: Failed to determine realpath of '/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.3.sdk' (errno=No such file or directory)
git: error: sh -c '/Applications/Xcode.app/Contents/Developer/usr/bin/xcodebuild -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.3.sdk -find git 2> /dev/null' failed with exit code 16384: (null) (errno=No such file or directory)
xcode-select: Failed to locate 'git', requesting installation of command line developer tools.
In my case, Xcode updated to v14.1 and my Mac is running macOS 12.6. I'm not positive that those two things are related, but you can see above that the macOS SDK that xcodebuild is looking for is MacOSX12.3.sdk.
xcode-select -p returns
/Applications/Xcode.app/Contents/Developer, which is what Xcode 14 configured automatically. (Changing this via
sudo xcode-select --switch /Library/Developer/CommandLineTools fixes git, but breaks other things in subtle ways (like some CocoaPods commands).)
The key here seems to be to copy the older, "missing" macOS SDK version into the Xcode folder structure so that everyone is happy.
Ideally, there would be some way to just have git point to the updated macOS SDK version, but I haven't figured that one out yet. Maybe upgrading to Ventura would fix that, but I haven't had the time to test that yet...