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.

有帮助吗?

解决方案

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'
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top