I run the command xcode-select --install, and I accept the license agreement, but then the system popups a message dialog saying "Can't install the software because it is not currently available from the Software Update server". So my git still does not work (the problem started after having upgraded to Mojave and XCode 10.1)
– nbloqsOct 31 '18 at 11:52

7 Answers
7

This will download and install xcode developer tools and fix the problem.

You do not need Xcode, you can install only the Command Line Tools here, it is about 130Mb.

The problem is that one needs to explicitly agree to the license agreement. As a follow on step, you may need to reset the path to Xcode if you have several versions or want the command line tools to run without Xcode.

You'll need to log in with your Apple ID in order to complete the download.
– james.garrissDec 20 '16 at 12:29

Yes. But for me that's not the issue. The issue is that I don't want to install full Xcode. I'll update the answer with this info
– michalczukmDec 20 '16 at 15:02

2

@michalczukm I'm on macOS 10.12.5 and installed the latest version (I think it was CLT for macOS 10.12 for Xcode 8.3) and it worked fine. Problem solved, thank you.
– Mark SimpsonJun 13 '17 at 9:48

2

Running xcode-select --install, as the other answer states, doesn't install Xcode, just the command line tools.
– setholopolusDec 6 '17 at 19:42

4

For macOS Mojave, xcode-select --install didn't work for me. But Since 30 July 2018, you can get the newest version of command line tools for macOS 10.4 (Mojave) once you login into the Apple Developer Account.
– Agile BeanAug 3 '18 at 16:52

Next I needed to upgrade xcode tools to the latest version: sudo softwareupdate -ia --verbose (NB: this runs all available updates from the app store, there is a way to specify that you only want to update one app/program, but I don't know it off the top of my head).

You can try this command another time if it shows some inconsistent behaviour during the first try.

Finally verify that it worked by using a git command of your choosing, e.g. git status.

The accepted answer is correct, but also note that git does not make it obvious if the error is coming from remote or from local. If you are running OS X on your remote, your install problem may be on the remote side and you'll see the same error on git clone and git pull but NOT on git status.

Thank you for your interest in this question.
Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).