Check if a directory is a git repository

1

I'm doing a small project with git and PHP through the library GIT.php , however I do not know what command to use, or how I can check if a directory is a repository.

I have tried to use git rev-parse <path> but I have not been successful, I have also tried to check if the .git directory exists but that does not necessarily mean that it is a repository.

What I want to achieve is to check if a specific directory is a repository, for example:

git [comando] <directorio>

Any suggestions on how I can achieve it?

    
asked by Juan Pinzón 10.06.2016 в 17:29
source

1 answer

2

I recommend running git status . If it is not a repository (Even if you create the directory .git manually), you will have the following message:

  

fatal: Not a git repository (or any of the parent directories): .git

If it works, you will have the following message:

  

On branch <rama> .

    
answered by 10.06.2016 / 17:32
source