def is_git_dir(d):
    if isdir(d):
        if isdir(join(d, 'objects')) and isdir(join(d, 'refs')):
            headref = join(d, 'HEAD')
            return isfile(headref) or \
                (os.path.islink(headref) and
                 os.readlink(headref).startswith('refs'))
        elif isfile(join(d, 'gitdir')) and isfile(join(d, 'commondir')) and isfile(join(d, 'gitfile')):
            raise WorkTreeRepositoryUnsupported(d)
    return False
This is taken from the git setup.c:is_git_directory
dataset/ETHPy150Open gitpython-developers/GitPython/git/repo/fun.py/is_git_dir