How could I tell a give directory is git repo(bare or not bare) in Python

StackOverflow https://stackoverflow.com/questions/23666742

  •  22-07-2023
  •  | 
  •  

문제

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