def read_gitfile(f):
    """Read a ``.git`` file.

    The first line of the file should start with "gitdir: "

    :param f: File-like object to read from
    :return: A path
    """
    cs = f.read()
    if not cs.startswith(b'gitdir: '):
        raise ValueError("Expected file to start with 'gitdir: '")
    return cs[len(b'gitdir: '):].rstrip(b'\n')
