from pathlib import Path


def is_repo(path: Path):
    """ Checks if the given path is in a github repository by detecting a .git directory.
    
    Starting at the given path, the tree is traversed recursively until the .git is found,
    or the root of the file tree is reached.

    Args:
        path (Path): path to a directory
    
    Returns:
        str: path to root of the repository, None otherwise
    """
    parent_path = path.parent
    while path != parent_path:
        if (path / '.git').exists():
            return path
        path = parent_path
        parent_path = path.parent
    return None