Question

Is there any way to tell if a directory is a GIT repo in Python?

I am try to check if there's ".git" under that directory, but it doesn't work with bare repo.

Was it helpful?

Solution

You can use GitPython:

from git import Repo, InvalidGitRepositoryError

try:
    Repo(path_to_repo)
    print 'is git repo'
except InvalidGitRepositoryError:
    print 'isn`t git repo'
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top