After a quick Google search, I found that many people had success by writing:
xcode-select --install
I get a message that asks me if I would like to install the Command Line Developer Tools, so I select install and agree to the terms. However, I then get a message that says:
“Can’t install the software because it is not currently available from the Software Update server.”
So after another Google search, I tried writing:
sudo xcode-select --reset
I enter my password, and then select enter, and nothing visibly changes. So I try writing git, and then xcode-select --install again, and the same thing keeps happening over and over in a circle.
With similar searches the folks who still couldn’t get things to work all seemed to wind up downloading the xcode dev tools as a .dmg and using the installer.
Given address was https://developer.apple.com/download/more/ but that may be outdated so have a little look around yourself.
I get the impression it’s something to do with a disjoint between the os and the xcode version but that’s a guess. Either way double checking both of these are updated isn’t a bad shout.