This problem occurs due to Xcode command-line tools are not updated.
For updating Xcode command-line tools
Goto terminal and use the following command:
xcode-select --install
Then it shows
xcode-select: note: install requested for command line developer tools
And opens a window to update Xcode command-line tools.
After the update is completed, open a new terminal window and your development tools should be returned.
After the update you need to restart your terminal to apply the updates then the function works properly.
Reference:https://developer.apple.com/library/archive/technotes/tn2339/_index.html
For more information regarding git commands, like git status, git clone, git merge, etc. please go through this tutorial.