To print the current branch:
print(repo.head.ref)
To list branches
print [str(b) for b in repo.heads]
To checkout a branch
repo.heads[branch].checkout()
or repo.git.checkout(branch)
If you're trying to delete a branch, You need to be in a different LOCAL branch, which you can do in several ways
repo.heads['master'].checkout()
or repo.git.checkout('master')
or repo.git.checkout('remotes/origin/master')
Hope this helps