Solve xcrun: error: invalid active developer path when using git on macOS High Sierra

After updating to macOS High Sierra, it may encounter following error when using git or other commands.

xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun  

To solve this problem, in your terminal, run the following command to install xcode command line.

xcode-select --install  

References:
Xcode IDE