Even on "correctly" configured systems, this and similar error messagemessages may be caused by temporary changes to the system environment. This intermittent behavior can be confusing to troubleshoot, but reverting or avoiding the problematic environment changes should correct the issue.
Examples:
- On SLURM systems,
module load-ing certain software may mis-configure the environment for git, yielding this error. If loading a module causes this error,module del <the_module>should resolve the problem. - OP's issue was caused by modifying environment variables. A "fresh" terminal session (with original env configuration) corrected the issue, as would reverting the affected environment variables.