GitPython repo.git.checkout无法正确检出分支

时间:2019-04-16 12:05:19

标签: gitpython

我正在使用以下代码在python代码中签出或切换分支,

repo.git.checkout('branch_name')

但是当以后执行代码时,仍指的是“主”分支代码。

我正在使用GitPython版本2.1.11。

1 个答案:

答案 0 :(得分:0)

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