def checkout(repository, target):
    """
    Check out target into the current directory.
    Target can be a branch, review Id, or commit.

    :param repository: Current git repository.
    :param target: Review ID, commit, branch.
    :return: Return the most recent commit ID (top of the git log).
    """
    repository.git.fetch([next(iter(repository.remotes)), target])
    repository.git.checkout('FETCH_HEAD')
    return repository.git.rev_parse(['--short', 'HEAD']).encode('ascii',
        'ignore')
