I want to use pygit2
to checkout a branch-name.
For example, if I have two branches: master
and new
and HEAD
is at master
, I would expect to be able to do:
import pygit2
repository = pygit2.Repository('.git')
repository.checkout('new')
or even
import pygit2
repository = pygit2.Repository('.git')
repository.lookup_branch('new').checkout()
but neither works and the pygit2 docs don't mention how to checkout a branch.
It seems you can do:
import pygit2
repo = pygit2.Repository('.git')
branch = repo.lookup_branch('new')
ref = repo.lookup_reference(branch.name)
repo.checkout(ref)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With