def is_git_repo ( ) : cmd = "git" , "rev-parse" , "--git-dir" try : subprocess . run ( cmd , stdout = subprocess . DEVNULL , check = True ) return True except subprocess . CalledProcessError : return False
python check for git
Check whether the current folder is a Git repo .
def is_git_repo():
    """Check whether the current folder is a Git repo."""
    cmd = "git", "rev-parse", "--git-dir"
    try:
        subprocess.run(cmd, stdout=subprocess.DEVNULL, check=True)
        return True
    except subprocess.CalledProcessError:
        return False