Check if directory is git repository (without having to cd into it)
Use git -C <path> rev-parse
. It will return 0 if the directory at <path>
is a git repository and an error code otherwise.
Further Reading:
rev-parse
-C <path>
We can also try git status
command and if the output is like :
fatal: Not a git repository (or any of the parent directories): .git
Then, the directory is not a git repository.