Do a git checkout of `ref` in `repo_dir`.

    If branch is specified it should be the name of the new branch.

def git_checkout(repo_dir, ref, branch=None):
    """Do a git checkout of `ref` in `repo_dir`.

    If branch is specified it should be the name of the new branch.
    """
    command = ['git', 'checkout', '--force']
    if branch:
        command.extend(['-B', '{}'.format(branch)])
    command.append(ref)
    return execute_git_command(command, repo_dir=repo_dir)