<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 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)