Quantcast
Viewing all articles
Browse latest Browse all 4

Answer by Mark Riggins for Using GitPython module to get remote HEAD branch

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


Viewing all articles
Browse latest Browse all 4

Trending Articles