def METHOD_NAME(repo, branch):
  """Check out a branch."""
  remote_branch = repo.lookup_branch('origin/' + branch,
                                     pygit2.GIT_BRANCH_REMOTE)
  local_branch = repo.lookup_branch(branch, pygit2.GIT_BRANCH_LOCAL)
  if not local_branch:
    local_branch = repo.branches.create(branch, commit=remote_branch.peel())
  local_branch.upstream = remote_branch
  local_branch.set_target(remote_branch.target)
  repo.checkout(local_branch)
  repo.reset(remote_branch.target, pygit2.GIT_RESET_HARD)