0

I am using following code to checkout or switch the branch within python code,

repo.git.checkout('branch_name')

But when the code later executes is still referring to 'master' branch code.

I am using GitPython version 2.1.11.

mate00
  • 2,727
  • 5
  • 26
  • 34

1 Answers1

1
import git
repo = git.Repo("/home/user/.emacs.d")

To checkout a branch:

  • to see available branches
>>> repo.heads
[<git.Head "refs/heads/master">, <git.Head "refs/heads/straight">]
  • you can use the branch name like this:
>>> repo.heads.straight.checkout()
<git.Head "refs/heads/straight">

the branch changed to straight

If you want to use git directly

>>> repo.git.checkout("master")
"Your branch is up-to-date with 'origin/master'."

the branch changed to master

azzamsa
  • 1,805
  • 2
  • 20
  • 28